Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / August 2005

Tip: Looking for answers? Try searching our database.

The select statement is in a field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George o - 31 Aug 2005 18:27 GMT
Ok, I inherited this database and there is a field that stopres a select
statement.  Is there anyway possible to execute the value of the field
within a select statement?

For example:

the table:
Name "george"
lookupForName "Select orders from Ordertable"

So maybe something like select name, execute(lookupforname) as orders

Sorry, I didn't design this, just inherited :)

george
Erland Sommarskog - 31 Aug 2005 23:14 GMT
> Ok, I inherited this database and there is a field that stopres a select
> statement.  Is there anyway possible to execute the value of the field
[quoted text clipped - 7 lines]
>
> So maybe something like select name, execute(lookupforname) as orders

You would have to do something like:

  SELECT @sql = lookupforname FROM tbl WHERE name = 'george'
  EXEC(@sql)

If you really want to add another column to that result set, it may get
ugly. If the SELECT statements does not have a WHERE clause you could
add "CROSS JOIN (SELECT name = ''george'')". Else you have to splice
it in into the query.

For more information on dynamic SQL, see this article on my web site:
http://www.sommarskog.se/dynamic_sql.html.

Signature

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.