Vikrant More
Vikrant More

Reputation: 5442

What is the difference between using 0 and 0x0 in SQL Server?

Hi i am using SQL Server 2012.Recently i was working on getting count of rows from each table for a Database.I found there were 4 different ways to get that but the 1 which is fast i found is using Partition stats i.e. "dm_db_partition_stats" and "sys.objects". However while making join i see in where condition it used like "is_ms_shipped=0x0". My question is there any difference between using "is_ms_shipped=0" and "is_ms_shipped=0x0" ? can somebody please help me to get this?

Upvotes: 1

Views: 2708

Answers (1)

Martin Smith
Martin Smith

Reputation: 453358

0x0 is a literal of datatype varbinary(1) and value 0x00. (A single byte with all bits set to 0).

The binary datatypes have the lowest data type precedence so if compared against a bit column it will get implicitly cast to that datatype. Resulting in 0.

You should just use 0 as it avoids the implicit cast and unnecessary obfuscation of using 0x0.

Upvotes: 4

Related Questions