关于存储过程中的情况
我有以下查询。
declare @Prm_CourseId int
declare @Prm_SpecializationId int
set @Prm_CourseId=5
set @Prm_SpecializationId=0
declare @WhrStr varchar(500)
set @WhrStr = case @Prm_CourseId
when 0 then
'e.CourseId is null or e.CourseId is not null'
when -1 then
'e.CourseId is null or e.CourseId is not null'
when isnull(@Prm_CourseId,0) then
'e.CourseId is null or e.CourseId is not null'
else
'e.CourseId= '+Convert(varchar,@Prm_CourseId)
end
set @WhrStr = case @Prm_SpecializationId
when 0 then
'e.SpecializationId is null or e.SpecializationId is not null'
when -1 then
'e.SpecializationId is null or e.SpecializationId is not null'
when isnull(@Prm_SpecializationId,0) then
'e.SpecializationId is null or e.SpecializationId is not null'
else
'e.SpecializationId= '+Convert(varchar,@ Prm_SpecializationId)
end
print @WhrStr
exec(
'select f.EnquiryID,
e.[Name],
f.AttendedBy,
f.Remarks,
f.CreatedDate
from STD_FollowUp f
inner join
STD_Enquiry e
on f.EnquiryId=e.EnquiryId
where'+' '+@WhrStr
)
这里的问题是我想在 @WhrStr 中的第一个和第二个 case 语句中获得结果。但是 WhrStr 中传入的值是“e.SpecializationId 为 null 或 e.SpecializationId 不为 null”意味着第一个被第二个覆盖。无论如何将第二个附加到第一个。
I have following query.
declare @Prm_CourseId int
declare @Prm_SpecializationId int
set @Prm_CourseId=5
set @Prm_SpecializationId=0
declare @WhrStr varchar(500)
set @WhrStr = case @Prm_CourseId
when 0 then
'e.CourseId is null or e.CourseId is not null'
when -1 then
'e.CourseId is null or e.CourseId is not null'
when isnull(@Prm_CourseId,0) then
'e.CourseId is null or e.CourseId is not null'
else
'e.CourseId= '+Convert(varchar,@Prm_CourseId)
end
set @WhrStr = case @Prm_SpecializationId
when 0 then
'e.SpecializationId is null or e.SpecializationId is not null'
when -1 then
'e.SpecializationId is null or e.SpecializationId is not null'
when isnull(@Prm_SpecializationId,0) then
'e.SpecializationId is null or e.SpecializationId is not null'
else
'e.SpecializationId= '+Convert(varchar,@ Prm_SpecializationId)
end
print @WhrStr
exec(
'select f.EnquiryID,
e.[Name],
f.AttendedBy,
f.Remarks,
f.CreatedDate
from STD_FollowUp f
inner join
STD_Enquiry e
on f.EnquiryId=e.EnquiryId
where'+' '+@WhrStr
)
here the problem is i want to get result in 1st and 2nd case statement in @WhrStr .But the value coming in WhrStr is 'e.SpecializationId is null or e.SpecializationId is not null' means 1st is overwritten by second.Is there anyway to append second to first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这在几个层面上都行不通。
CASE WHEN 位需要位于字符串分隔符“
...THEN”中
'(e.CourseId 为 null 或 e.CourseId 不为 null)'...
“e.CourseId is null or e.CourseId is not null”是相同的“总是给我数据”< /p>“e.CourseId
您需要的是:
This won't work in several levels.
The CASE WHEN bit needs to be in string delimiters "
...THEN
'(e.CourseId is null or e.CourseId is not null)'...
"e.CourseId is null or e.CourseId is not null" is the same "always give me data"
All you need is: