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

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

dsthompson
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.

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
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

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 12/06/2012 :  01:33:24  Show Profile  Reply with Quote
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 - 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000