Please start any new threads on our new site at http://forums.sqlteam.com. 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!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Variable select statement
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

james_b
Starting Member

9 Posts

Posted - 09/07/2004 :  13:06:45  Show Profile  Reply with Quote
I have a select statement as follows:

select table_name, table_row_id from Table_Link

That produces:

Organization, 1
Organization, 2
Organization, 3
Country, 1
Country, 2

etc

What I need to do is select the data from the relevant table and row_id in the same step, producing something similar to this pseudo-code:

Organization, 1, (select name from organization table where row_id = 1)
Organization, 2, (select name from organization table where row_id = 2)
Organization, 3, (select name from organization table where row_id = 3)
Country, 1, (select name from country table where row_id = 1)
Country, 2, (select name from country table where row_id = 2)

So the second half of the sql statement depends on the values that the first half retrieves...

hope this makes sense, thanks for any help :)

James

spirit1
Cybernetic Yak Master

Slovenia
11752 Posts

Posted - 09/07/2004 :  13:53:01  Show Profile  Visit spirit1's Homepage  Reply with Quote
will this help?

select table_name, table_row_id, '(select name from' + table_name + ' where row_id = ' + table_row_id + ')'
from Table_Link

Go with the flow & have fun! Else fight the flow
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.05 seconds. Powered By: Snitz Forums 2000