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
 Select null

Author  Topic 

akamole
Starting Member

17 Posts

Posted - 2014-02-27 : 03:17:02
select strFastbeteckningTrakt + ' ' + strFastbeteckningBlock + strFastbeteckningTecken + convert(VARCHAR(10), intFastbeteckningEnhet) as Fastighet, strAnlnr

Will mostly give desired result:

Fastighet strAnlnr
HEDBY 2:3 45678

But for some rows these can be null:
strFastbeteckningBlock
strFastbeteckningTecken

which will cause this:

Fastighet strAnlnr
NULL 45678


when i want this:

Fastighet strAnlnr
HEDBY 3 45678

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-27 : 05:17:27
use ISNULL()

select ISNULL(strFastbeteckningTrakt + ' ', '')
+ ISNULL(strFastbeteckningBlock, '')
+ ISNULL(strFastbeteckningTecken, '')
+ convert(VARCHAR(10), ISNULL(intFastbeteckningEnhet,'')) as Fastighet, strAnlnr



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

Go to Top of Page

akamole
Starting Member

17 Posts

Posted - 2014-02-27 : 07:55:40
Thank you!
Go to Top of Page
   

- Advertisement -