sql server - In stored procedure if null value found it should skip that insert query -


i have 2 tables 1

peson contains(personid identity, firstname,lastname,placeofbirth,gender)  

and

education contains (eduid identity, egreename,boarduniver,yearofpassing,obtainedmarks, personid) 

now problem each person have more 1 degree, have 1 or 2 degree, how can skip insert queries?

first table

create table person(personid int identity(1,1) primary key, firstname nvarchar(40), lastname nvarchar(40), placeofbirth nvarchar(40), gender nvarchar(10)) 

second table

create table education(eduid int identity(1,1) primary key, degreename nvarchar(40), boarduniver nvarchar(40), yearofpassing nvarchar(40), obtainedmarks numeric(10,2), personid int,  constraint fk_eduperson foreign key (personid) references person(personid)) 

procedure store information

create procedure empdetails (     @firstname nvarchar(40),  @lastname nvarchar(40), @placeofbirth nvarchar(40), @gender nvarchar(8),      @degreename0 int, @boarduniver0 nvarchar(40), @yearofpassing0 nvarchar(20), @obtainedmarks0 int,     @degreename1 int, @boarduniver1 nvarchar(40), @yearofpassing1 nvarchar(20), @obtainedmarks1 int,     @degreename2 int, @boarduniver2 nvarchar(40), @yearofpassing2 nvarchar(20), @obtainedmarks2 int,  ) begin declare @personid int insert person(firstname,lastname,placeofbirth,gender) values(@firstname,@lastname,@placeofbirth,@gender) select @personid=@@identity if(@degreename0 !=null)     begin     insert education(degreename,boarduniver,yearofpassing,obtainedmarks, personid) values (@degreename0,@boarduniver0,@yearofpassing0,@obtainedmarks0, @personid)     end if(@degreename1 !=null)   begin     insert education(degreename,boarduniver,yearofpassing,obtainedmarks, personid) values (@degreename1,@boarduniver1,@yearofpassing1,@obtainedmarks1, @personid)   end if(@degreename2!=null)    begin     insert education(degreename,boarduniver,yearofpassing,obtainedmarks, personid) values (@degreename2,@boarduniver2,@yearofpassing2,@obtainedmarks2,@personid)     end end 

this not working.. inserts rows empty.. there other solution this? please give suggestion if other..

try is not null instead of != null. in relational databases, comparison operators return false if either input null, if both are. here sql fiddle demonstrating behavior.

(sorry. sql fiddle works.)

admittedly, confusing, fact should mean inserts skipped. don't see here insert empty rows.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -