I have the below sql query which I am using on sql server.
select distinct [Value],Label,Id from(
select distinct [Name], Code, I as Id,I + ':' + [Value] as label, [Value]
from [test].[dbo].[emp]
unpivot
(
[Value]
for I in (product, model)
) as dataTable) as t
What I want to have is if any [Value]
inside unpivot statement is null, it should return 'unknown' to the nested select statement.
How do I achieve it ?
Update--
//this is wrong sql. Just want to show what is required
select distinct [Value],Label,Id from(
select distinct [Name], Code, coalesce(I as Id,'unknown'),coalesce(I,'unknown') + ':' + [Value] as label, coalesce([Value],'unknown')
from [test].[dbo].[emp]
unpivot
(
[Value]
for I in (product, model)
) as dataTable) as t