Q:

What is the difference when parsing between Tab and Spaces in sql server 2008 R2

I have encountered a scenario below
Declare @var int = '       123'  
select @var

Declare @var1 int = '      123'  
select @var1  

for the first case I have used spaces in front of the value and while execute it returns value as 123  
In Second case I have used tab instead of space in front of value and while execute it throws conversion error  
Can anyone let know what is the difference between these 2 scenario..

A:

Even though you have put same number of spaces (using spaces and then Tab) the character codes for both of them is different and that is the reason that space and TAB are treated as separately in SQL Server.  
More information about character codes and character encoding can be found at below 2 links:-
https://www.computerhope.com/jargon/c/charcode.htm
https://www.pcmag.com/encyclopedia/term/51983/standards-character-codes
Also if you think mathematically and logically:- having spaces before integer numbers does not make sense.  It's like having zeros before numbers.  
For Example:-'     123' (5 spaces and then 123) is like 00000123.  
Yet one more reason that spaces are trimmed before the integer numbers

