Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 emptablehow to write query in stored procedureFriend
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