Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Contrary of ISNULL() ? Expand / Collapse
Author
Message
Posted Thursday, September 03, 2009 5:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 05, 2009 1:42 AM
Points: 6, Visits: 11
Hello everyone,

how can I display something when a specific field value is not null ?

That of course wont work:
SELECT *, ISNOTNULL(Authordate,'Last Upload: ') + ISNULL(Authordate,'') From Documents

Any suggestions ?

Sascha

Post #782069
Posted Thursday, September 03, 2009 5:31 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:54 AM
Points: 37,726, Visits: 29,985
SELECT < Column list >,
CASE WHEN AuthorDate IS NULL THEN '' ELSE 'Last Upload: ' + CONVERT(VARCHAR(30), AuthorDate, < Appropriate formatting code >) END
FROM Documents




Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #782082
Posted Thursday, September 03, 2009 7:21 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, January 24, 2013 8:54 PM
Points: 710, Visits: 1,518
Same principal different code provided CONCAT_NULL_YIELDS_NULL is ON.

SELECT ISNULL('Last Upload: ' + CONVERT(VARCHAR, AuthorDate+'', 112), '')
FROM Documents

Dave
Post #782141
Posted Saturday, September 05, 2009 1:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 05, 2009 1:42 AM
Points: 6, Visits: 11
Thank you both for your fast help, justanewone i used your solution its works fine !

Sascha
Post #783276
Posted Saturday, September 05, 2009 9:49 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 32,906, Visits: 26,793
how can I display something when a specific field value is not null ?


I see the examples of code folks gave you but they aren't really required. If the field is NOT null, it will display... no? Most systems will display a NULL as a blank and don't require a conversion to a blank or empty string. You'll save clock cycles in the process.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #783344
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse