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
 General SQL Server Forums
 New to SQL Server Programming
 execute command from rows

Author  Topic 

j0shua
Starting Member

40 Posts

Posted - 2009-02-18 : 00:01:05
if data are saved in a row or records like

column1
1 select * from table1
2 select * from table2....table nth

Is there a way to execute these?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-18 : 00:07:06
you need to use dynamic sql for this. also a loop or cursor is reqd to traverse row by row. why are you storing statements themselves in table?
Go to Top of Page

j0shua
Starting Member

40 Posts

Posted - 2009-02-18 : 00:16:57
i am actually looking for a way to select a specific data in all tables from this code


SELECT 'SELECT * FROM ' + QUOTENAME(TABLE_NAME)
+ ' WHERE ' + QUOTENAME(COLUMN_NAME)
+ '=''11223344-5566-7788-99AA-BBCCDDEEFF00'''
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE DATA_TYPE='uniqueidentifier'
AND EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME=c.TABLE_NAME and TABLE_TYPE='BASE TABLE')


and i am looking for ways to execute these, thanks!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-18 : 01:52:06
just copy paste the result of above query into another query window and execute
Go to Top of Page
   

- Advertisement -