Home > Net >  Count ISNULL convert to varchar
Count ISNULL convert to varchar

Time:11-20

I have this query

SELECT   
    COUNT(ISNULL(TRY_CAST(item AS nvarchar), 'Unknown')) AS [col], 
    item
FROM
    table1
GROUP BY
    item

And I get this result:

col item
---------
2   NULL
1   100

Not sure why NULL won't change to 'Unknown'.

Can you point out the wrong query? Thank you

CodePudding user response:

Your select statement is off, and you presumably wanted this:

SELECT ISNULL(TRY_CAST(item AS nvarchar), 'Unknown') AS item, COUNT(*) AS cnt
FROM table1
GROUP BY ISNULL(TRY_CAST(item AS nvarchar), 'Unknown');
  • Related