Sql-server – SQL Server compact- Query that return 2 constant columns even if query didn’t return data

sql serversql-server-compactt-sql

Please look at the following simple query:

Select CustomerID
From Customers c  
Where  c.CustomerId = "1234"

I want to write similar query that does the following:

Always return 2 columns with constant string instead of CustomerID in this structure:

If value was found then return 2 columns:
Found Value in DB, CustomerId

Else return:
Didn't found value in DB, CustomerId

How can I do that? Especially in Microsoft compact SQL server limited syntax…

Best Answer

Derived tables and Case statements are supported in SQL CE, so you can use this script

Select 
case 
when s.custs = 0 then 'Didnt found value in DB'
else 'found value in DB'
end
,'customer id'
from 
(select COUNT(*) as 'custs' from Customers c Where  c.CustomerId = 1234) s

for reference check what can and what cannot be used in SQL CE