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)
 Building a dynamic record on the fly... possible?

Author  Topic 

jkeneally
Starting Member

1 Post

Posted - 2007-08-07 : 09:29:52
I'm not sure if this is possible in SQL 2005 but...

I have a table of Fields, and a table of FieldValues.

I can select all the fields and all the values in one query and get results that look like this:

Field Name | Field Value
------------------------
First_Name | John
Last_Name | Doe
Address | 21 Jump Street

Is it possible to build a record on the fly, in a stored proc that would return one record that looks like this? The names/values can be dynamic, so I never know how many there are until I run the query.


First_Name | Last_Name | Address
------------------------------------
John | Doe | 21 Jump Street


Ultimately there will be alot of data returned at once and I want to return one record for each set of name/val pairs that go together
instead of a query that returns hundreds of name/val pairs and the code has to group them toghether

thanks for any help

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-08-07 : 09:58:17
Yes, you can. However, this is a display issue. Do this in the front end application.

Otherwise, do a search for Cross Tab Reporting.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -