In my sql server I got a table named "Product" where a column named "P_name" exist. This column is completely null meaning it has null value in all of its rows eg:
P_name |
---|
NULL |
NULL |
NULL |
I wrote two queries. My first query is:
declare @value int
select value = count(P_name) from Product
It returned the value of 0 (which is correct because the P_name column is completely null)
I wrote the second query as follows:
declare @colName nvarchar(max) = 'P_name';
declare @value int
select value = count(@colName) from Product
This returned a value with 3 (which I suppose is wrong)
Isn't both query snippets are same and suppose to return the same value in my case 0? Why they are producing two different values?