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 |
|
liangtp@hotmail.com
Starting Member
27 Posts |
Posted - 2008-09-22 : 04:55:51
|
| Hi guys,I wish to dynamically create a var table based on the result of an SQL query. Example below.select Names From tableResult:1.Clinton2.Obama3.McCainHow shall I write my code so that the result would have the similar following effect:declare @varTable table (Clinton nvarchar(10),Obama nvarchar(10),McCain nvarchar(10))Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 04:58:52
|
| Ok. so your columns will be data from table. so what should be data in it? What you need is crosstabed result. |
 |
|
|
liangtp@hotmail.com
Starting Member
27 Posts |
Posted - 2008-09-22 : 05:01:45
|
| you are right. it is a 2-Dimensional cross tab result. I need to capture some counter value data. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 05:06:19
|
quote: Originally posted by liangtp@hotmail.com you are right. it is a 2-Dimensional cross tab result. I need to capture some counter value data.
Use PIVOT operator available in SQL 2005. Have a look at books online for syntax and usagehttp://msdn.microsoft.com/en-us/library/ms177410.aspx |
 |
|
|
liangtp@hotmail.com
Starting Member
27 Posts |
Posted - 2008-09-22 : 05:23:00
|
| Allright. Thank you. |
 |
|
|
|
|
|