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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ISNULL checks for all fields

Author  Topic 

phaze
Starting Member

42 Posts

Posted - 2010-01-21 : 11:09:28
I have the following stored proc and trying to figure out how i would do a check for NULLs around all of the fields. I am pretty new at this.

Thanks

CREATE PROCEDURE [dbo].[pr_SegmentID_update_Edit]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

UPDATE ad
SET nSegmentID =
CASE
WHEN cChargeOffReason = '10' AND nRecoveryScore >= 526 THEN 1
WHEN cChargeOffReason = '10' AND nRecoveryScore < 526 THEN 2
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo = 'Y' AND
c.accountid IS NOT NULL AND nRecoveryScore BETWEEN 485 AND 525 THEN 3
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo <> 'Y' AND
c.accountid IS NOT NULL AND nRecoveryScore >= 526 THEN 4
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo = 'Y' AND
c.accountid IS NOT NULL AND nRecoveryScore >= 526 THEN 5
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo <> 'Y' AND
c.accountid IS NULL AND nRecoveryScore >= 526 THEN 6
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo = 'Y' AND
c.accountid IS NULL AND nRecoveryScore BETWEEN 485 AND 525 THEN 7
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo = 'Y' AND
c.accountid IS NULL AND nRecoveryScore >= 526 THEN 8
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo <> 'Y' AND
c.accountid IS NULL AND nRecoveryScore < 526 THEN 9
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo <> 'Y' AND
c.accountid IS NOT NULL AND nRecoveryScore < 526 THEN 10
WHEN cChargeOffReason <> '10' AND cVoluntaryRepo = 'Y' AND
nRecoveryScore BETWEEN 436 AND 484 THEN 11
ELSE 12
END
FROM Stg_Accountdaily ad
LEFT JOIN CONTACT c ON c.accountid = ad.accountid AND c.contactTypeid in(5,6,13,16)
END

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-01-21 : 12:42:23
WHERE COALESCE(Col1, Col2, Col3, ...) IS NULL



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-01-21 : 12:46:09
You could use the ISNULL function, which will replace NULL with a value that you can specify
An example is :
DECLARE @var1 varchar(20)
SET @var1 = NULL
UPDATE myTABLE set myCol = ISNULL(@var1,'a-replace-value')

Jack Vamvas
--------------------
http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -