SQL Coalesce in Linq syntax

  • Thread starter Thread starter Dean Slindee
  • Start date Start date
D

Dean Slindee

How would the following SQL Coalesce statement need to be written in Linq to
SQL:
SELECT COALESCE(LastName, '') + ' '
+ COALESCE(FirstName, '') + ' '
+ COALESCE(MiddleName, '') + ' '
+ COALESCE(SuffixName, '') AS ClientName,
ClientID
FROM tblClient
WHERE LastName LIKE @Letter + '%'
ORDER BY ClientName

Thanks,
Dean Slindee
 
Dean said:
How would the following SQL Coalesce statement need to be written in
Linq to SQL: SELECT COALESCE(LastName, '') + ' '
+ COALESCE(FirstName, '') + ' '
+ COALESCE(MiddleName, '') + ' '
+ COALESCE(SuffixName, '') AS ClientName,
ClientID
FROM tblClient
WHERE LastName LIKE @Letter + '%'
ORDER BY ClientName

Thanks,
Dean Slindee

Use the '??' operator in C#

so:
var q= from c in nw.Customer
select new
{
FirstName = c.FirstName??''
//...

};

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Frans,

Zit je je daar een beet je zondag avond uit te sloven of ben je nog niet
vertrokken?

Sorry fellows, had to be in Dutch

Cor
 
Here is another way in VB:
Dim query = From tblClient In dc.tblClients _
Where tblClient.LastName.StartsWith(s1) _
Order By tblClient.LastName, tblClient.FirstName,
tblClient.MiddleName _
Select ClientName = tblClient.LastName & " " & _
If(tblClient.FirstName, "") & "
" & _
If(tblClient.MiddleName, "") & "
" & _
If(tblClient.SuffixName, ""), _
tblClient.ClientID
 
Cor said:
Frans,

Zit je je daar een beet je zondag avond uit te sloven of ben je nog
niet vertrokken?

Ik ga dit jaar niet naar de summit :)

FB
Sorry fellows, had to be in Dutch

Cor


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Back
Top