Sunday, 15 August 2010

mssql 2008 - using variables as column names -


I searched a lot to use variable names in the form of column names, although I could not find anything . I have a table in which the name is the master column and the passable, yVariable, zVariable below. I know I can use it: Name nameMaster when 'xVariable' then xVariable case name as the total and 0 end when the 'yVariable' then the total and the end of the form of 0 In yverable case nameMaster when 'zVariable' then zVariable as the total and 0 end

Although I want to do it in a loop, not manually

My table is like this:

  Nominee | Total --------------------- xVariable | 10.000 yVariable | 20.000 zVariable | 30.000   

What I want to show is like this:

  xVariable | YVariable | ZVariable --------------------------------- 10.000 20.000 30.000   

thanks advance ..

Okay, what you want to achieve is called PIVOT table and it Your columns will change in rows based on your column selections.

You can see the article how pivot is.

No comments:

Post a Comment