>Hi.
>I am having trouble with syntax Of Transact Sql
>I want to Select particular Column names, depending on the Data
>Pseudoi Code is:
>
>Select ;
> MyFIled1, MYfiled2,MyFileld3,MyValue1,
> Case:
> If MyField1 = '10', MyValue1 as MyNewColumn01
> If MyField1 = '20' MyValue1 as MyNewColumn02
> If MyField1 = '30' MyValue1 as MyNewColumn03
> Endcase
>
>I also want to ensure that I ALWAYS end up with MyNewColumn01,MyNewColumn02,MyColumn03 even if of dont have the value in MyFileld1 (e.g. say I have only two rows with MyField1 = 1, and 2 I still want to create a zero column value called MynewColumn03
>
>I know this can probably be done with the Pivot function, but can i do it with the Case id If statement ?
>
>Tia
>Gerard
For PIVOT try
select [10] as MyNewColumn01, [20] as MyNewColumn02, [30] as MyNewColumn3
from dbo.myTable PIVOT (max(MyValue1) FOR myField1 IN ([10],[20],[30])) pvt
If it's not broken, fix it until it is.
My Blog