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)
 Must declare the scalar variable "@Assigned_Server

Author  Topic 

Shilpa22
Starting Member

37 Posts

Posted - 2009-03-08 : 06:49:08
Hi All,

When I try to execute my below stored proc its throwing an error..
Must declare the scalar variable "@Assigned_Server


alter procedure proc_sel_TitleDesc_SendEmails
(
@NoOfParameters varchar(5),
@Assigned_Server varchar(50)
)
as
declare @query varchar(500)
set @query = 'select top ' + cast(@NoOfParameters as varchar(5)) + ' m.message_id,m.title,m.message_Desc from message m,sendemails s where m.message_id = s.message_id and s.status=1000 and s.Email_Status=1 and s.assigned_server = @Assigned_Server'
exec(@query)
GO

What am I doing wrong here?

Please help me out..

THanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-08 : 07:18:44
s.assigned_server = ' + quotename(@Assigned_Server, '''')


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Shilpa22
Starting Member

37 Posts

Posted - 2009-03-08 : 09:06:55
Bravo!!!
it resolved..
Thanks for helping me..

Thanks in Advance
Shilpa
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-08 : 12:49:47
quote:
Originally posted by Shilpa22

Bravo!!!
it resolved..
Thanks for helping me..

Thanks in Advance
Shilpa


also see this to understand about dynamic sql

http://www.sommarskog.se/dynamic_sql.html
Go to Top of Page
   

- Advertisement -