I tried @somevalue = null and it worked that time. But now its not working. How to check if the value is null?
In brief what I need to do is if @existPerson is equal to null then INSERT the values into the database. But if it exists then return -2. I have checked in the database made sure that there are no same value as @nic = 100. Even so its returning me -2. What could be the possible reason ? Thanks a lot!
CREATE PROCEDURE [dbo].[addStudent]
@stuName varchar(50),
@address varchar(100),
@tel varchar(15),
@etel varchar(15),
@nic varchar (10),
@dob date
AS
BEGIN
SET NOCOUNT ON;
DECLARE @currentID INT
DECLARE @existPerson INT
SET @existPerson = (SELECT p_ID FROM Student WHERE s_NIC = @nic);
IF @existPerson = null
BEGIN
INSERT INTO Person (p_Name, p_RegDate, p_Address, p_Tel, p_EmergeNo, p_Valid, p_Userlevel)
VALUES (@stuName, GETDATE(), @address, @tel, @etel, 0, 'Student' );
SET @currentID = (SELECT MAX( p_ID) FROM Person);
INSERT INTO Student (p_ID, s_Barcode, s_DOB, s_NIC) VALUES (@currentID , NULL, @dob, @nic);
return 0;
END
ELSE
return -2;
END
this should be
in sql if you want to check value is null or not than you need use
is nulloris not nullinstead of= nullor<> null