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
 if else

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2008-03-17 : 17:13:09
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 ON
set QUOTED_IDENTIFIER ON
go





ALTER PROCEDURE [dbo].[InsertNOAAppr]
@NOAID int,
@AppraisalCompany varchar(50),
@AppraisalFee decimal(18,2),
@DownPayment decimal(18,2)=NULL,
@AppraisalClientResponsibility char(1) =NULL

AS
BEGIN

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 NULL
BEGIN
INSERT into NOAAppr(NOAId,ApprFee,ApprComp)
Values
(@NOAID,@AppraisalFee,@AppraisalCompany)
END
ELSE
BEGIN
INSERT into NOAAppr(NOAId,ApprFee,ApprComp,DwnPymt,ApprClntResp)
Values
(@NOAID,@AppraisalFee,@AppraisalCompany,@DownPayment,@AppraisalClientResponsibility)
END
Go to Top of Page

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.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-03-18 : 09:38:35
What's with {???????}




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -