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.
| Author |
Topic |
|
macca
Posting Yak Master
146 Posts |
Posted - 2011-12-14 : 11:33:39
|
| I am running a simple select statement.SELECT distinct a.Id, a.Registration_No, Convert(nvarchar(15), a.ticket_date, 106) as ticket_date_text, a.Forename + ' ' + a.Surname as Name FROM tblTickets aThe problem I am having is that a.Forename and a.Surname can be NULL sometimes and if they are that record is not returned.Anyone know what I am missing?Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-14 : 11:35:46
|
| [code]SELECT distinct a.Id, a.Registration_No, Convert(nvarchar(15), a.ticket_date, 106) as ticket_date_text, COALESCE(a.Forename + ' ','') +COALESCE( a.Surname,'') as Name FROM tblTickets a[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2011-12-15 : 03:14:35
|
| Hi,When we concatenate any variable/ column with some other variable/ column, if any one of the value is NULL then the result will be a NULL.For Ex:DECLARE @V1 VARCHAR(10) = NULLDECLARE @V2 VARCHAR(5) = 'HAI'SELECT @V1 + @V2RESULT : NULLSELECT COALESCE(@V1, '') + COALESCE(@V2, '')RESULT : HAISo use ISNULL OR COALESCE Statement while concatenating values. SQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
 |
|
|
|
|
|
|
|