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
 Slicker coding please (Solved)

Author  Topic 

Bill_C
Constraint Violating Yak Guru

299 Posts

Posted - 2009-03-19 : 03:16:41
Hi

Anyone got a slicker method of doing this please:-


SET @code = (SELECT MAX(DATALENGTH([code]))
IF @code = 0
BEGIN
SET @code = 1
END
IF @code IS NULL
BEGIN
SET @code = 1
END


I am looking to set the variable (one of many) to 1 if the result of SELECT MAX(DATALENGTH returns 0 or NULL.

Should i maybe be using a CASE statement or is there something better/faster?

Thanks, just trying to speed up my code.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-19 : 04:03:24
[code]SELECT @Code = COALESCE(NULLIF(MAX(DATALENGTH(Col1)), 0), 1)
FROM Table1[/code]


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

Bill_C
Constraint Violating Yak Guru

299 Posts

Posted - 2009-03-19 : 04:11:13
cracking!
Thanks, that's what I was looking for, a one liner solves all!
Go to Top of Page
   

- Advertisement -