SQL Server – Casting Integers to Asterisk

SQL Server – Casting Integers to Asterisk

An odd ‘feature’ of T-SQL that once sent me on a wild goose chase. If you try to cast an integer to a smaller length char/varchar data type, the database engine silently casts the value to an asterisk ‘*’. This is also true for when you rely on an implicit cast such as during an Insert.





Postgres also silently casts the values without returning an error but behaves like it does with character data – by truncating the values:




A little more sensible I think.

Leave a Reply

Your email address will not be published. Required fields are marked *