存储过程拼接字符串
ALTERPROCEDUREdbo.Staff_Select@StaffNamenvarchar(30)=NULL,@Sexnvarchar(10)=NULLAS/*SE...
ALTER PROCEDURE dbo.Staff_Select
@StaffName nvarchar(30)=NULL,
@Sex nvarchar(10)=NULL
AS
/* SET NOCOUNT ON */
DECLARE @CONDITION nvarchar(1000)
SET @CONDITION = 'SELECT * FROM Staff WHERE 1=1'
IF @StaffName IS NOT NULL
SET @CONDITION = @CONDITION + ' AND StaffName='+''''+@StaffName+''''
IF @Sex IS NOT NULL
SET @CONDITION = @CONDITION + ' AND Sex='+''''+@Sex+''''
EXEC(@CONDITION)
RETURN
按照网上的说法,拼接时只需要三个’,但我的却要报错,用四个‘(上面正确)就是正常的!求解......... 展开
@StaffName nvarchar(30)=NULL,
@Sex nvarchar(10)=NULL
AS
/* SET NOCOUNT ON */
DECLARE @CONDITION nvarchar(1000)
SET @CONDITION = 'SELECT * FROM Staff WHERE 1=1'
IF @StaffName IS NOT NULL
SET @CONDITION = @CONDITION + ' AND StaffName='+''''+@StaffName+''''
IF @Sex IS NOT NULL
SET @CONDITION = @CONDITION + ' AND Sex='+''''+@Sex+''''
EXEC(@CONDITION)
RETURN
按照网上的说法,拼接时只需要三个’,但我的却要报错,用四个‘(上面正确)就是正常的!求解......... 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询