Author |
Topic |
brindaam
Starting Member
4 Posts |
Posted - 2010-12-13 : 08:35:21
|
Hi,I have two queries, say for exampleSelect distinct 0 parent_id, ROW_NUMBER() OVER( ORDER BY Column2_Desc ) AS 'ID', Column2_DescFrom table1UnionSelect distinct 0 parent_id, ROW_NUMBER() OVER( ORDER BY Column2_Desc ) AS 'ID', Column2_DescFrom table2I don’t have relationship between two tables.But I want to frame parent child relationship between these two so that my resultset should likeParent_id id Column2_Desc0 1 ABC0 2 XYZ0 3 ASDF1 4 VGTY2 5 DFT I don’t want to use stored procedure.Kindly Help Me OutBrinda |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-13 : 09:04:11
|
Can you post the table structure and some sample data ? |
|
|
X002548
Not Just a Number
15586 Posts |
|
brindaam
Starting Member
4 Posts |
Posted - 2010-12-14 : 00:10:48
|
Hi,This is what the structure of my tableRow_id column2_desc column31 ABC XYZ2 ASDF ZSERquote: Originally posted by pk_bohra Can you post the table structure and some sample data ?
Brinda |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-12-14 : 00:18:26
|
can you post the sample data together with the corresponding expected result ?what is the relationship between table 1 and 2 ? And what is the parent - child relationship here ? KH[spoiler]Time is always against us[/spoiler] |
|
|
brindaam
Starting Member
4 Posts |
Posted - 2010-12-14 : 00:20:18
|
Hi,i have included the data alsoquote: Originally posted by khtan can you post the sample data together with the corresponding expected result ? KH[spoiler]Time is always against us[/spoiler]
Brinda |
|
|
brindaam
Starting Member
4 Posts |
Posted - 2010-12-14 : 02:41:38
|
Hi ,I have a Table as below,ID Column1 Column2 Column31 ABC ZXC AAA2 123 ASDF BBB3 DERT ASDER ASDFAnd I need the output like thisID PARENTID HEADERTEXT1 NULL ABC2 NULL 1233 NULL DERT4 1 ZXC5 2 ASDF6 3 ASDER7 4 AAA8 5 BBB9 6 ASDFquote: Originally posted by khtan can you post the sample data together with the corresponding expected result ?what is the relationship between table 1 and 2 ? And what is the parent - child relationship here ? KH[spoiler]Time is always against us[/spoiler]
Brinda |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-12-14 : 16:28:57
|
[code]DECLARE @Sample TABLE ( ID INT, Column1 VARCHAR(20), Column2 VARCHAR(20), Column3 VARCHAR(20) )INSERT @SampleSELECT 1, 'ABC', 'ZXC', 'AAA' UNION ALLSELECT 2, '123', 'ASDF', 'BBB' UNION ALLSELECT 3, 'DERT', 'ASDER', 'ASDF'SELECT ID, NULL AS PARENTID, Column1 AS HEADERTEXTFROM @SampleUNION ALLSELECT ID + COUNT(*) OVER (), ID, Column2FROM @SampleUNION ALLSELECT ID + 2 * COUNT(*) OVER (), ID + COUNT(*) OVER (), Column3FROM @Sample[/code] N 56°04'39.26"E 12°55'05.63" |
|
|
|