Built In Bugs :: VarChar

Alexander Kuznetsov pointed this one out on his blog. He goes on to a longer explanation and how to test for the issue in general (see link). SS

In Transact SQL you can assign a 10-character value to a VARCHAR(5) variable, as follows:

DECLARE @c VARCHAR(5); SET @c='1234567890'; PRINT @c


The value will be silently truncated without raising an error. Because of this behavior it may be very easy to make mistakes.


Please use comments ...

Many management types continually rant about leaving comments in the code so that the next person will be able to figure out what is going on. Sometimes it just proves something else ...

'* Comments: IMPORTANT: The global constants are being temporarily prefaced with "" until
'* all the reports can be integrated with calls to the delegate methods. Afterwards,
'* a global search/replace of "" with "" should rename the constants to coding
'* standards compliancy.

License & copyright

Creative Commons License
StinkySQL weblog and any related pages, including the weblog's archives are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.