Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 "Virtual" Tables Query.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 12/05/2012 :  11:35:02  Show Profile  Reply with Quote
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.


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


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.


Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 12/05/2012 :  11:43:33  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/06/2012 :  01:33:24  Show Profile  Reply with Quote
see this

SQL Server MVP

Go to Top of Page

Starting Member

2 Posts

Posted - 12/10/2012 :  15:32:06  Show Profile  Reply with Quote
Thanks guys. You were very helpful.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000