当前位置: 代码迷 >> Sql Server >> 大侠们,看看这个存储过程解决办法
  详细解决方案

大侠们,看看这个存储过程解决办法

热度:55   发布时间:2016-04-27 14:13:11.0
大侠们,看看这个存储过程
SQL code
ALTER proc [dbo].[proc_GetPrjWhere]    @Dptid int = null,    @Userid int = null,    @PrjCode varchar(20) = null,    @BCreatdate datetime = null,    @ECreatdate datetime = nullasdeclare @where varchar(200)set @where = '1=1'if(@Dptid is not null and @Userid is null)beginset @where = 'Dptid ='+LTRIM(@Dptid)endif(@Userid is not null and @Dptid is not null)beginset @where ='Userid ='+LTRIM(@Userid)+' and Dptid ='+LTRIM(@Dptid)endif(@PrjCode is not null)beginset @where ='PrjCode = [email protected]endexec('select * from Info_prjvalues where [email protected]+'')


[b][/b]执行后[size=24px][/size]
消息 207,级别 16,状态 1,第 1 行
列名 '有间客栈' 无效。

(1 行受影响)

------解决方案--------------------
set @where ='PrjCode = [email protected]+''''
------解决方案--------------------
ALTER proc [dbo].[proc_GetPrjWhere]
@Dptid int = null,
@Userid int = null,
@PrjCode varchar(20) = null,
@BCreatdate datetime = null,
@ECreatdate datetime = null
as
declare @where varchar(200)
set @where = '1=1'
if(@Dptid is not null and @Userid is null)
begin
set @where = 'Dptid ='+LTRIM(@Dptid)
end
if(@Userid is not null and @Dptid is not null)
begin
set @where ='Userid ='+LTRIM(@Userid)+' and Dptid ='+LTRIM(@Dptid)
end
if(@PrjCode is not null)
begin
set 'PrjCode = [email protected]+''''
end
print 'select * from Info_prjvalues where [email protected]+'' --print 
exec('select * from Info_prjvalues where [email protected]+'')
  相关解决方案