存储过程参数判断为空有关问题
存储过程参数判断为空问题
现在我把三个参数都付了值 但是查不出数据
直接写sql语句又能查出数据
求解!!
------最佳解决方案--------------------
你可以改一下,看有没有进入你的if 判断
------其他解决方案--------------------
看起来没什么问题 用楼上的测试一下 看看有没有结果
------其他解决方案--------------------
if exists(select 1 from Contact where [A]=@a and month([c])=month(@c))--这里还需要加一个日期月份判断
------其他解决方案--------------------
没错 就这么整
------其他解决方案--------------------
谢谢大伙 这个问题已经解决了
现在还有个问题 如下:
ALTER procedure [dbo].[Pro_1]
@A varchar(50),
@B varchar(50),
@C datetime, --日期格式
@Remark1 varchar(50),
@Remark2 varchar(50)
as
begin
if exists(select 1 from Contact where [A]=@a and [c]=@c)--这里还需要加一个日期月份判断
begin
return 0--已存在
end
else
begin
insert into Contact([A],[B],[C],[Remark1],[Remark2])
Values(@A,@B,@C,@Remark1,@Remark2)
ALTER PROCEDURE [dbo].[Pro_SelectItem]
@User_Name varchar(50),
@qItemTime datetime,
@dItemTime datetime
as
if(isnull(@User_Name,'')='' and ISNULL(@qItemTime,'')<>'' and ISNULL(@dItemTime,'')<>'')
begin
select ine.ItemBz,ine.ItemName,ine.Itemint,ine.ItemTime,su.User_Name,itd.ItemName from
ItemName as ine inner join Sys_user as su on ine.Ubz=su.Ubz inner join ItemDate as itd on ine.ItemName=itd.ItemBz
where ine.ItemTime between @qItemTime and @dItemTime
end
if(isnull(@User_Name,'')<>'' and ISNULL(@qItemTime,'')<>'' and ISNULL(@dItemTime,'')<>'')
begin
select ine.ItemBz,ine.ItemName,ine.Itemint,ine.ItemTime,su.User_Name,itd.ItemName from
ItemName as ine inner join Sys_user as su on ine.Ubz=su.Ubz inner join ItemDate as itd on ine.ItemName=itd.ItemBz
where ine.ItemTime between @qItemTime and @dItemTime and su.Ubz=@User_Name
end
现在我把三个参数都付了值 但是查不出数据
直接写sql语句又能查出数据
求解!!
------最佳解决方案--------------------
你可以改一下,看有没有进入你的if 判断
if(isnull(@User_Name,'')='' and ISNULL(@qItemTime,'')<>'' and ISNULL(@dItemTime,'')<>'')
begin
print 1
end
if(isnull(@User_Name,'')<>'' and ISNULL(@qItemTime,'')<>'' and ISNULL(@dItemTime,'')<>'')
begin
print 2
end
------其他解决方案--------------------
看起来没什么问题 用楼上的测试一下 看看有没有结果
------其他解决方案--------------------
if exists(select 1 from Contact where [A]=@a and month([c])=month(@c))--这里还需要加一个日期月份判断
------其他解决方案--------------------
没错 就这么整
------其他解决方案--------------------
谢谢大伙 这个问题已经解决了
现在还有个问题 如下:
ALTER procedure [dbo].[Pro_1]
@A varchar(50),
@B varchar(50),
@C datetime, --日期格式
@Remark1 varchar(50),
@Remark2 varchar(50)
as
begin
if exists(select 1 from Contact where [A]=@a and [c]=@c)--这里还需要加一个日期月份判断
begin
return 0--已存在
end
else
begin
insert into Contact([A],[B],[C],[Remark1],[Remark2])
Values(@A,@B,@C,@Remark1,@Remark2)