create PROCEDURE  up_CheckProductIsHave
 @p_Nmae(70)
 @p_Code(20)
AS
    if exists 
(select P_Name from dbo.tb_Products where P_Name like %@p_Nmae% or P_DfCode=@p_Code)
return 1
else
return 0消息 102,级别 15,状态 1,过程 up_CheckProductIsHave,第 2 行
'(' 附近有语法错误。
消息 102,级别 15,状态 1,过程 up_CheckProductIsHave,第 6 行
'@p_Nmae' 附近有语法错误。

解决方案 »

  1.   

    create PROCEDURE  up_CheckProductIsHave
     @p_Nmae(70)
     @p_Code(20)
    AS
    begin 
    declare @strSql as nvarchar(1000)
    declare @iRet as int

    select @strSql=N'select top 1 @iRe=1 from dbo.tb_Products where P_Name like ''%'+@p_Nmae+'%'' or P_DfCode='''+@p_Code''''

    exec sp_executesql @strsql,N'@iRet int output',@iRet output

    return isnull(@iRet,0)
    end试试 你这种情况要动态执行 
      

  2.   

    like @p_Nmae可以在@p_Nmae 变量里面存放‘%name%’
      

  3.   

    create PROCEDURE  up_CheckProductIsHave
     @p_Nmae nvarchar(70),
     @p_Code nvarchar(20)
    AS
    begin 
        declare @strSql as nvarchar(1000)
        declare @iRet as int
        
        select @strSql=N'select top 1 @iRe=1 from dbo.tb_Products where P_Name like '+'%'''+@p_Nmae+'''%'+' or P_DfCode=''+@p_Code'''
        
        exec sp_executesql @strsql,N'@iRet int output',@iRet output
        
        return isnull(@iRet,0)
    end