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.
I am trying to use an if else construct in my Stored procedure.It is giving errors.What I am trying to achieve is this. Check for a parameter whether it is null or not then based on that do insert. My procedure is given below. Please help me fix this .set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER PROCEDURE [dbo].[InsertNOAAppr] @NOAID int, @AppraisalCompany varchar(50), @AppraisalFee decimal(18,2), @DownPayment decimal(18,2)=NULL, @AppraisalClientResponsibility char(1) =NULL ASBEGIN SET NOCOUNT ON;if @DownPayment isnull{ INSERT into NOAAppr(NOAId,ApprFee,ApprComp)Values (@NOAID,@AppraisalFee,@AppraisalCompany)}[else { INSERT into NOAAppr(NOAId,ApprFee,ApprComp,DwnPymt,ApprClntResp)Values (@NOAID,@AppraisalFee,@AppraisalCompany,@DownPayment,@AppraisalClientResponsibility)}]END
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2008-03-17 : 18:01:00
try this:
IF @DownPayment IS NULLBEGIN INSERT into NOAAppr(NOAId,ApprFee,ApprComp) Values (@NOAID,@AppraisalFee,@AppraisalCompany)ENDELSEBEGIN INSERT into NOAAppr(NOAId,ApprFee,ApprComp,DwnPymt,ApprClntResp) Values (@NOAID,@AppraisalFee,@AppraisalCompany,@DownPayment,@AppraisalClientResponsibility)END
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-03-18 : 07:01:06
IS NULL & ISNULL() function are different. IS NULL is actually a comparison operator equivalent to =NULL while ISNULL() is function which is used to replace NULL values with some other values.