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)
 dynamic sql in a column

Author  Topic 

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-10-14 : 09:27:00
Hello All,

I have a sql tableA in SQL 2005 which has one of the column containing sql statements. I wanted to execute these sqls and write result in the corrosponding columns.

Col1 Col2
select count(*) from table1 10600
select count(*) from table2 988
select count(*) from table3 19887
select count(*) from table4 40

Is there an easy way to accomplish this instead of using cursor?

I have to do the same thing on sql 2000 as well.

Appreciate your help.

Thanks in advace,
-P

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-14 : 09:29:13
Nope, you have to use a CURSOR or a WHILE loop.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-10-14 : 11:18:01
Thanks for your reply Peso. But I thought there should be some way to execute the statements from column and write the result to corrosponding column.

Thanks,
-P
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-14 : 11:21:30
why is system designed like this?
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-10-14 : 11:29:01
It is not the design. I have to validate the replication data. To do that, I am building the sql statements using sysarticels table with the filters and storing them in a column (example - select count(*) from Table1 where ID = 0). Compare the record counts at publisher and subscriber to validate the data.

Thanks,
-P
Go to Top of Page
   

- Advertisement -