As you know NULL is the absence of data and any datatype can be NULL. But by default a NULL value is considered to be of INT datatype. Let us run the following code
select null as t into #t
exec tempdb..sp_help #t
A NULL value is copied to a temporary table #t. Second resultset of sp_help of #t shows that the column t is of INT datatype. As NULL is not explicitely converted to any datatype, by default SQL Server treats it as INT datatype. So you need to be aware of this. If you want it to be specific datatype, you need to explicitely convert it to different datatype as shown in the below code
select cast(null as datetime) as t into #t1
exec tempdb..sp_help #t1
Tags: t-sql, sql_server, null, sqlserver, tsql, SQL Server, data_type, #SQL SERVER,
It's a very nice article to know NULL, a bit more.
Thanks for the post sir.
That's really interesting! Thank-you for the post, Madhivanan!
Interesting. Thanks for sharing.
Found this article , to display null values at the end of the sorted table instead of first
case when column_name is null then 1 else 0 end
Interesting! Thanks for sharing!