Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert statement?

Author  Topic 

friend
Starting Member

6 Posts

Posted - 2012-01-21 : 09:01:11
Hi all,

i have a table called emptable columns are(empid,empname,sal,deptid)

if deptid is not null then i have to insert into table (emptable)
else don't insert the record into the table emptable
how to write query in stored procedure

Friend

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-21 : 09:06:21
How are you getting the data to be inserted? Assuming that they are in variables, you can do this:

if (@deptid is not null)
begin
insert into emptable (empid, empname, sal, deptid)
values (@empid, @empname, @sal, @deptid)
end
Here the variable names are @empid, @empname, @sal, @deptid

Go to Top of Page
   

- Advertisement -