它没有进入if循环 [英] its not entering the if loop

查看:70
本文介绍了它没有进入if循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALTER PROCEDURE [dbo].[employeegeofence2]
@employeename varchar(64),
@basestationame varchar(64),
@superuserid varchar(64),
@creationdate datetime
AS
begin
Declare @emp as varchar(50)
Declare @empid as varchar(50)

select @empid=tag_id from  student_master where First_Name=@employeename
print @empid
select @emp=First_Name from student_master where First_Name=@employeename
print @emp

if(@emp = '' ) line5
begin
print'sucess'
end
else
begin
prnit 'inserted'
end
SET NOCOUNT ON;
END


我面临的问题是表中不存在empid和empname,因此应在if循环内输入它,但不能输入并以n行5的形式成功打印.
我给了(@ emp = null),然后它也没有进入if循环,只有else被执行,否则有人会帮助我.


The issue I face is that empid and the empname do not exist in the table so it should enter inside the if loop, but its not entering and printing success as n line 5.
I gave (@emp=null) then also its not enetring the if loop only the else gets executed anyone help me out.

推荐答案

您可以将默认值初始化为@emp如下.
You may initialize default value to @emp as below.
Set @emp = '';


可能在student_master表中没有针对您为参数@employeename传递的值的记录.

或者,您可以根据以下count保留支票.


Probably their is no records in your student_master Table for the value you are passing for parameter @employeename.

Or you may keep your check on the basis of count as below.

Declare @empCount as int;

select @empCount=count(First_Name) from student_master where First_Name=@employeename;

if(@empCount=0) 
begin
  print'sucess'
end
else
begin
  prnit 'inserted'
end


如果表中不存在First_Name(即没有数据) ,它将返回NULL,而不是".

如果要用空字符串替换NULL,请检查一下isull(FIELD,'''')函数.
If First_Name doesn''t exist in the table (ie, there''s no data), it''s going to return NULL, not ''''.

Check out the isnull(FIELD, '''') function if you want to replace NULL with an empty string.


这篇关于它没有进入if循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆