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)
 Is there any way to execute a sql query

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-08-20 : 02:01:02
Is There any simple way to execute a query,
Currently I have been using
EXEC sp_executeSql

and before calling it, I was just replacing the 1st Select with 'Select @output=' but when caller SP provided me a query like

WITH MyTable(Col1) as
(
select Col1 from table1
union
Select Col1 from table2
)
select Col1 from MyTable where MyCondition

the replacement logic is failed because it replaced the First Select which is written with in the WITH

Now I am looking for any SP/Function that can execute my Query as it is(and I dont want to manipulate it) and it should give me the result in a variable

Is there any solution for this????

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 02:07:28
try this out:-
replace(Yourquery,') select Col1',') Select @output= Col1')
Go to Top of Page
   

- Advertisement -