Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

The select statement is in a field
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(lookupfornam
e) as orders

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

george



Report this thread to moderator Post Follow-up to this message
Old Post
George o
08-31-05 06:24 PM


Re: The select statement is in a field
George o (george.nospamogrady@hp.com)  writes:
> 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(lookupfornam
e) 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.

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

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


Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
09-01-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 02:35 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006