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-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:43 AM
Points: 41,517, Visits: 34,434
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: Monday, April 14, 2014 7:45 AM
Points: 710, Visits: 1,524
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: Yesterday @ 10:21 PM
Points: 35,951, Visits: 30,235
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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #783344
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse