daniwell
daniwell
2017-08-18 11:19

数据库创建存储过程后,执行语句出错

  • 存储
  • 数据库
  • sql

数据库为sql 2008

创建存储过程语句
create proc myOrderInfo_1
(
@s_OrderId int ,
@s_totalPrice float,
@s_OrderDate date,
@s_payMode varchar(50)
)
as
begin
set nocount on;
DECLARE @MyParm NVARCHAR(MAX) ,
@sqlcommand NVARCHAR(MAX)

    SET @sqlcommand = 'SELECT [OrderId],
                              [TotalPrice],
                              [OrderDate],
                              [PayMode]
                        FROM [dbo].[OrderInfo] 
                        where 1=1 '
   IF(@s_OrderId IS NOT NULL)
        SET @sqlcommand = cast(@sqlcommand as varchar)+'AND OrderId=@s_OrderId'

    IF(@s_totalPrice IS NOT NULL)
        SET @sqlcommand = cast(@sqlcommand as varchar)+'AND TotalPrice=@s_totalPrice'

    IF(@s_OrderDate IS NOT NULL)
        SET @sqlcommand = cast(@sqlcommand as varchar)+'AND OrderDate>=@s_OrderDate'

   IF(@s_payMode IS NOT NULL)
        SET @sqlcommand = cast(@sqlcommand as varchar)+'AND PayMode>=@s_payMode'

    SET @MyParm= ' @s_OrderId1 int ,
                 @s_totalPrice1 float,
                 @s_OrderDate1 date,
                 @s_payMode1 varchar(50) '


    PRINT @sqlcommand
    EXEC sp_executesql @sqlcommand,@MyParm,
                         @s_OrderId      =    @s_OrderId,
                         @s_totalPrice   =    @s_totalPrice,
                         @s_OrderDate    =    @s_OrderDate,
                         @s_payMode      =    @s_payMode

end

错误:图片说明 想不通哪错了,。。。。求大神解答

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答