Hi Friends
I have a sql question, We have the source data as below.
101 address1, address2, address3
and the output shoulb like below
101 address1
101 address2
101 address3
Required a SQL query for this output.
Please let me know if you have any sql query for this.
Thanks in advance.
Hari M
Answers were Sorted based on User's Feedback
Answer / vennela12
Hi Hari.....try this
select 101,address1 from tablet1
union all
select 101,address2 from tablet1
union all
select 101,address from tablet1
By
Vennela
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / ronak
You have to use LPAD function,
Select lpad(address,20,'101')
from tableName;
NOTE: address is column name of address info, 20 is total
characters you want to display including 101 (since in this
case we don't know the characters of address),
Thank you
Ronak
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / ksks
Make use of UNPIVOT to split one record into many rows:
select id,address from T1 unpivot (address for address_type in (address1,address2,address3))
Is This Answer Correct ? | 1 Yes | 0 No |
Hi Vennala
The posted query will work fine. But what if incase 'N'
no.of columns, like address1, address2..., address n.
The query will become lenghty with N no.of Unions.
Is there any script or procedure as alternative??
Please help me out in this regard.
Thanks,
Hari
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / tdguy
Hi Hari,
IF the source data is present in a file, then it can
be handled in the supporting OS say unix or mainframe,
whichever is being used. But the input data is present in a
single column, then i think UDF has to be used.
Is This Answer Correct ? | 0 Yes | 0 No |
Define views in teradata with general syntax.
Comment whether bottleneck is an error or not.
What are the differences between TerdataV2R5 and V12 Versions please??
"pravalli nagireddy" record is there in address column but i want display only 'nagireddy' from the main string what is query for that pls tell me
What is bteq utility in teradata?
How do you do backup and recovery in teradata?
Hi All, I have a table with 3 fields like id,mark1,mark2 and I would like to update a mark3 field that would calculate the max for each record (so the max value of the 2 fields) in Teradata ID Mark1 Mark2 Mark3 1 10 20 2 20 30 3 40 10 4 50 50 I Have to write a update statement Mark3 with max value of mark1,mark2 fields…like bellow ID Mark1 Mark2 Mark3 1 10 20 20 2 20 30 30 3 40 10 40 4 50 50 50 Please any one help me ....Thq
Explain the term 'foreign key' related to relational database management system?
What are the uses of bynets in multi-node systems?
List out teradata data types?
What is the purpose of upsert command?
Find 2 highest sal from each dept who have completed 5 year in org