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)
 Simple EXEC Query

Author  Topic 

mapidea
Posting Yak Master

124 Posts

Posted - 2010-02-17 : 19:05:18
ALTER PROCEDURE [dbo].dvx_5_DocToDoc_MoveOrder_UpgradeQueue
@orders_status_id INT,
@order_ids VARCHAR(3000)
AS
DECLARE @Sql VARCHAR(1000)

SET @Sql = 'UPDATE Orders
SET orders_status_id=' + @orders_status_id + '
WHERE order_id IN (' + @order_ids + ')'

EXEC (@Sql)


When I run dvx_5_DocToDoc_MoveOrder_UpgradeQueue -9, '562478,562479'

It gives this error.

Msg 245, Level 16, State 1, Procedure dvx_5_DocToDoc_MoveOrder_UpgradeQueue, Line 30
Conversion failed when converting the varchar value 'UPDATE Orders
SET orders_status_id=' to data type int.

What Am I missing?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-17 : 19:07:45
You'll need to explicitly convert @orders_status_id to varchar using CONVERT function.

You should use a CSV function though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2010-02-17 : 19:11:48
Thanks a lot Tara.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-17 : 19:27:08
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-18 : 01:03:40
if you dont want to use dynamic sql, you can do like this


ALTER PROCEDURE [dbo].dvx_5_DocToDoc_MoveOrder_UpgradeQueue
@orders_status_id INT,
@order_ids VARCHAR(3000)
AS
UPDATE Orders
SET orders_status_id= @orders_status_id
WHERE ','+ @order_ids + ',' LIKE '%,' + CAST(order_id AS varchar(15)) + ',%'
GO


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -