存储过程参数判断为空问题
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)
return 1--表示成功
end
end
这个判断条件 得加一个条件现在
判断 日期中的月份是否与表中的日期月份有相同的
传过来的格式是datetime格式 表中也是日期格式 怎么只截取其中的月份进行比较
求解!!
[其他解释]
谢了
@A varchar(50),
@B varchar(50),
@C datetime, --日期格式
@Remark1 varchar(50),
@Remark2 varchar(50)
as
if exists(select 1 from Contact where [A]=@a and month([c])=month(@c))
{
//执行更新语句
//更新语句中这里的需要给字段B(表中的类型也是字符型)累加 传过来的@B是字符数字。 该怎么给字段B+@B
呢 这样?
update 表 set b+=@B where .... 是这样写吗?
}