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
 Transact-SQL (2000)
 Question on Dynamic SQL Query

Author  Topic 

aawan
Starting Member

24 Posts

Posted - 2005-08-30 : 12:37:14
I was wondering if someone could help me with a problem.

I'm attempting to do the following

declare @lastOrder int,
@stateName varchar(2),
@qryString varchar(255)

set @qryString = 'select @lastOrder = max(orderID) from CustomerOrders_'+@stateName+''

The error I get is that '@lastOrder' has not been declared.
But as you can see in the code above, it has been declared. What am I doing wrong?

Thanks,
Ali

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-30 : 12:43:21
You'll need to use sp_executesql with the OUTPUT option:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41413

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-30 : 13:03:10
http://weblogs.sqlteam.com/brettk/archive/2005/01/27/4029.aspx




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

aawan
Starting Member

24 Posts

Posted - 2005-08-30 : 13:21:48
Thanks Tara,

Whenever I have a question on this forum, you always seem to have the right answer, immediately.

I must say, you truly are the Almighty SQL Goddess :)

Thanks a bunch!
Ali
Go to Top of Page
   

- Advertisement -