Question : Pass through query with declare doesn't return records

I need a pass through query (to a SQL table) in where I have declared a variable.  I can run the query in Query Analyzer with a record returning, however as a pass through I get the message like 'Pass Through Query with ReturnRecords set to True did not return any records'.
I know I could do this as a StoredProcedure and then have the pass through 'exec sp_Name paramValue' but the sql statement is going to be generated in VBA depending on what is selected on a form.

The attached code is not the full statement I need, just testing if declare's worked
Code Snippet:
1:
2:
3:
4:
declare @ProjectID int
select  @ProjectID = 6233
 
Select * From Project Where ProjectID = @ProjectID

Answer : Pass through query with declare doesn't return records

If you have the @ProjectID in your SQL string you could always do a REPLACE() on it

strSQL = "Select * From Project Where ProjectID = @ProjectID"
strSQL = REPLACE(strSQL, "@ProjectID", "6233")

Cheers, Andrew

Random Solutions  
 
programming4us programming4us