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
 QUERY HELP

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-05-26 : 07:20:44
SELECT CASE
WHEN ID = '' THEN Isnull(Replace(DESCRIPTION, '', NULL), -999999999)
WHEN ID IS NULL THEN Isnull(DESCRIPTION, -999999999)
ELSE ID
END

FROM ABC


IS THIS QUERY CORRECT AND OPTIMIZED



PLEASE HELP THE BETTER WAY IF THIS CAN BE DONE .

challenge everything

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-26 : 08:41:14
quote:
IS THIS QUERY CORRECT

you didn't explain what are you trying to achieve, we can't really comment on that
quote:
AND OPTIMIZED

Did you post the full query ? If that is it, it is just a simple select statement. There is nothing much can be done to optimize it further.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

estaban
Starting Member

1 Post

Posted - 2012-05-26 : 15:20:09
SELECT CASE
WHEN ID = '' THEN Isnull(Replace(DESCRIPTION, '', NULL), -999999999)
WHEN ID IS NULL THEN Isnull(DESCRIPTION, -999999999)
ELSE ID
END AS SOMETHING

FROM ABC

Add bold words to your query and try again.

Emre CELIK
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-05-27 : 23:52:53
got it .. thanks estaban

challenge everything
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-05-30 : 03:34:01
or simply

SELECT ISNULL(NULLIF('',NULL),-999999999) AS SOMETHING FROM ABC

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -