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)
 CTE and passing a query as a parameter

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2008-02-21 : 17:55:58
Hi,

Is it possible for me to load my CTE with a query that I pass in as a parameter to the sproc? I'm trying it and it doesn't seem to work.

I'm doing:

CREATE PROCEDURE blah
@sql NTEXT

AS

WITH CTE(...) AS
(
EXEC sp_executesql @sql
)

select ...


What's wrong?

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-02-21 : 20:10:17
Not that I condone dynamic SQL, but why not just put the CTE stuff into the dynamic SQL?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-22 : 01:35:18
Why do you want to pass entire sql as parameter?
Make sure you read this fully
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -