Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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

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.
Posted
Updated 14-Nov-11 18:02pm
v3

You may initialize default value to @emp as below.
SQL
Set @emp = '';

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.
SQL
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
 
Share this answer
 
Comments
ashok_89 16-Nov-11 3:54am    
thanks a lot sir it worked for me
RaisKazi 16-Nov-11 3:56am    
Welcome. Cheers!
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.
 
Share this answer
 
Comments
ashok_89 15-Nov-11 0:09am    
always the inserted is only getting printed
_Damian S_ 15-Nov-11 0:41am    
Of course it is - that's the else part. The value is not '', it's NULL. NULL and '' are different.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900