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 |
|
omega1983
Starting Member
40 Posts |
Posted - 2009-11-24 : 11:27:00
|
| DECLARE @AttrHobby TABLE (attrkey numeric(13),attrid char(10),attrtype char(6),attrtypenm varchar(65),attrcomm varchar(4000))INSERT INTO @AttrHobby (attrkey,attrid,attrtype,attrtypenm,attrcomm)SELECT attrkey,attrid,attrtype,attrtypenm,attrcommFROM dbo.attribute where attrtype = 'hobby'and attrid = '0000006313'order by attrtypenmThis temp variable table produces the following outputattrkey attrid attrype attrtypenm attrcomm1234 0000006313 hobby hobby reading1235 0000006313 hobby hobby automobilesI know want to convert this to a crosstab, with data looking like thisattrid attrype attrcomm1 attrcomm20000006313 hobby reading automobilesI tried a max case statement but it lists the data vertically. This is because each attrkey produces a new line of data |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-24 : 11:32:42
|
You can search for PIVOT, maybe that helps. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-25 : 01:50:23
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|