Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mibheenick
Starting Member
12 Posts |
Posted - 2005-08-26 : 06:50:45
|
| Hi everyone out there!plz help am really tired looking for a solution to this!I have a View(vw_A) which return me values like the following:Num1 Typ1 Num2 Typ2 Num3 Typ3 ---- ---- ---- ---- ---- ----570 1 382 2 113 3571 1 382 2 113 3572 1 383 2 113 3I want to retrieve the column values in different rows as follows: case 1: Select * from vw_A where Num1 = 570 and Typ1 = 1EXPECTED result:Num1 Typ1 NumX TypX ---- ---- ---- ----570 1 382 2570 1 113 3case 2: Select * from vw_A where Num2 = 382 and Typ2 = 2EXPECTED result:Num2 Typ2 NumX TypX ---- ---- ---- ----382 2 570 1382 2 571 1382 2 113 3case 3: Select * from vw_A where Num3 = 113 and Typ3 = 3EXPECTED result:Num3 Typ3 NumX TypX ---- ---- ---- ----113 3 570 1113 3 571 1113 3 572 1113 3 382 2113 3 383 2I have to get these results in another View, so I cant use Temptables. Anyone plz help me out of this! Need to complete this at the earliest.Thanks in advance.... |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-26 : 07:01:52
|
| You can write query based on the viewSelect Num1,Typ1, Num2, Typ2 from vw_A where Num1=570Union allSelect Num1,Typ2, Num3, Typ3 from vw_A where Num1=570MadhivananFailing to plan is Planning to fail |
 |
|
|
kapilarya
Yak Posting Veteran
86 Posts |
Posted - 2005-08-28 : 11:02:43
|
| try some thing like this :select * from (select NUM1,TYPE1,NUM2,TYPE2 from vw_Aunionselect NUM1,TYPE1,NUM3,TYPE3 from vw_Aunionselect NUM2,TYPE2,NUM1,TYPE1 from vw_Aunionselect NUM2,TYPE2,NUM3,TYPE3 from vw_Aunionselect NUM3,TYPE3,NUM2,TYPE2 from vw_Aunionselect NUM3,TYPE3,NUM1,TYPE1 from vw_A) as xwhere NUM1 = 570 and Type1 = 1change the value of num1 in the query to 382, and type1 = 2 and then 113, and type1 = 3you will see the result that are asking forKapil Arya |
 |
|
|
|
|
|
|
|