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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 "Virtual" Tables Query.

Author  Topic 

dsthompson
Starting Member

2 Posts

Posted - 2012-12-05 : 11:35:02
I'm not really sure how to label the task before me so I'll just describe it. Hopefully it will be something people do every day (except for me).

I need to do a query that will return records where a column is actually a record in a single table holding multiple columns.

So...

Table A
-------
Column Name
Column Value
...
Record GUID

The "record" would be comprised of all the columns from Table A with matching GUIDs

So the result would be

Column A, Column B, Column C

Not

Column A
Column B
Column C

It sounds like a Pivot, but since the number of columns could be variable, it doesn't seem to fit into the stringent Pivot setup.

This is pretty much what the requirements are and I can't change them to something else. So while thoughtful suggestions on alternative approaches are appreciated, it is not within my power to implement them.

Thanks,

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-12-05 : 11:43:33
It is a pivot just not using the pivot statement (which I agree isn't all that usefull).
Have a look at dynamic sql. I think Robvolk has an article on here about creatoing a pivot getting the column details from the system tables.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-06 : 01:33:24
see this

http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dsthompson
Starting Member

2 Posts

Posted - 2012-12-10 : 15:32:06
Thanks guys. You were very helpful.
Go to Top of Page
   

- Advertisement -