日期:2014-05-17  浏览次数:20447 次

sql语句改为存储过程
update OrderPackageItem "
  + "set UseAmount = ProductAmount - i.ItemAmount "
  + "from OrderPackageItem p "
  + "join ( "
  + "select b.PackageItemId, sum(b.ItemAmount) as ItemAmount "
  + "from Orders a join OrderItems b on a.OrderId=b.OrderId "
  + "where a.OrderStatus = 1 and a.PackageId = {0} "
  + "group by b.PackageItemId ) i "
  + "on p.OrderPackageItemID = i.PackageItemId "
  + "where p.OrderPackageID = {0}; "
  + "update OrderPackage set State = 1 "
  + "where OrderPackageID = {0} and not "
  + "exists(select * from OrderPackageItem where OrderPackageID = {0} and UseAmount >0

麻烦大家帮小弟看看,这段sql语句怎么改成存储过程啊???

------解决方案--------------------
建立个存储过程,把这SQL语句放进去,然后参数部分用存储过程的传参
------解决方案--------------------
建立个存储过程,把你sql语句中的{0}或其他参数用传参的形式传进来

SQL code
ALTER PROCEDURE [dbo].[EDM_ChannelCreate]
           @ChnName nvarchar(50) ,...--你要需要什么参数 就传什么参数