Question of the month December 2015 – Why does this code return “*”?

Consider the following code

declare @v varchar(2)
set @v=100
select @v

The result is *. Why does it return * as a result?

Advertisements

4 thoughts on “Question of the month December 2015 – Why does this code return “*”?

  1. variable gets the value in numeric format. so that it converts the number into *. If we try to pass as a character then it will consider two digits of number set @v=’100′ This results 10

  2. Your variable @v is of varchar(2) and assign value 100 to it which is numeric and 3 character long. So when an integer value is too large which doesn’t fit in specific sized string then sql server convert it to “*’ result. Actually its error. If you try the same script with NVARCHAR(2) datatype then you’ll get the actual error.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s