I have two columns that I have to compare. if both or one column have Null then I need to have a new column to say "Y" and if both columns have information in it then the new column has 'N'
I tried using coalesce, but that returns whatever is not null in the new column. The case when doesn't work with how I'm writing it below.
Is there some other way of doing this? I been researching on-line can't seem to find anything. CASE WHEN doesn't work is there something I'm missing that might be able to work.
here's sample code from Advantage Works- the 2nd case doesn't work.
SELECT TOP 1000 [BusinessEntityID]
,[TerritoryID]
,[SalesQuota]
,[Bonus]
,[CommissionPct]
,[SalesYTD]
,[SalesLastYear]
,[rowguid]
,[ModifiedDate]
,COALESCE (TerritoryID,salesquota)
,case when TerritoryID = 2 and SalesQuota = 300000.00 then 'y' else 'n' end
,case when TerritoryID ISNULL and SalesQuota isnull then 'y' else 'n' end
FROM [AdventureWorks2012].[Sales].[SalesPerson]
colA ColB ColC 12 abc N null null Y 14 null Y
Aucun commentaire:
Enregistrer un commentaire