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 2000 Forums
 SQL Server Development (2000)
 subquery within dynamic SQL sproc?

Author  Topic 

steelkilt
Constraint Violating Yak Guru

255 Posts

Posted - 2003-06-06 : 14:39:13
Hi. I'm trying to place a subquery within my dynamic SQL sproc. This is a straitforward subquery for generating a list of customers who are found in the DEMOS table. I can't get the syntax correct. Suggestions? The piece you see below is the continuation of my original SELECT query, adding another filter...thx

BEGIN

SELECT @SQL = @SQL + ' AND '
SELECT @SQL = @SQL + ' Customer IN '
SELECT @SQL = @SQL + '(select Customer'
SELECT @SQL = @SQL + 'from'
SELECT @SQL = @SQL + @Demos
SELECT @SQL = @SQL + ')'


END



nr
SQLTeam MVY

12543 Posts

Posted - 2003-06-06 : 14:44:16
What is @Demos?

If it is a table variable then it is not available to the batch in which the sql is executed.
Make it a temp table and it will be OK.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -