纠正我的存储过程中的错误

时间:2011-05-12 05:52:36

标签: sql sql-server-2005

我在AS附近遇到错误在IF中出现了什么问题..?

Create Procedure dbo.sp_Normal_Search
(
@title as nvarchar(max),
@Description as nvarchar(max),
@Keywords as nvarchar(max),
@Chk_title as Bit,
@Chk_Description as Bit,
@Chk_Keywords as Bit,
@RD_AND as Bit,
@RD_OR as Bit



AS
if(@RD_AND = 1)
Begin
    if(@Chk_title = 1)
        Begin
        (Select title from server_des where title Like '%'+ @title+'%')
        End
END
GO
)

我在AS附近遇到错误在IF中出现了什么问题..?

2 个答案:

答案 0 :(得分:3)

括号在错误的地方:

Create Procedure dbo.sp_Normal_Search 
( 
   @title as nvarchar(max), 
   @Description as nvarchar(max), 
   @Keywords as nvarchar(max), 
   @Chk_title as Bit, 
   @Chk_Description as Bit, 
   @Chk_Keywords as Bit, 
   @RD_AND as Bit, 
   @RD_OR as Bit 
) 
AS

if @RD_AND = 1 
Begin 
    if @Chk_title = 1 
        Begin 
            Select title from server_des where title Like '%'+ @title+'%' 
        End 
END 
GO 

如果@RD_AND!= 1

,您打​​算返回什么?

答案 1 :(得分:1)

您需要在存储过程后删除括号....名称...

将其更改为:

Create Procedure dbo.sp_Normal_Search 
   @title as nvarchar(max), 
   @Description as nvarchar(max), 
   @Keywords as nvarchar(max), 
   @Chk_title as Bit, 
   @Chk_Description as Bit, 
   @Chk_Keywords as Bit, 
   @RD_AND as Bit, 
   @RD_OR as Bit 
AS

if @RD_AND = 1
Begin 
    if @Chk_title = 1
        Begin 
            Select title 
            from server_des 
            where title Like '%' + @title + '%'
        End 
END 
GO