dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Allow SQL Server to Silently Truncate Data

See two ways to prevent SQL from throwing this error.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


SQL Server usually presents an error on an attempt to insert more data into a field than it can hold. It typically throws an error message similar to the following:

Msg 8152, Level 16, State 14, Line 15
 String or binary data would be truncated.
 The statement has been terminated.

To prevent this (when needed, of course), you have two options:

Turn ANSI_WARNINGS off
    SET ANSI_WARNINGS {ON|OFF}

Pass through a variable

declare @testString varchar(5)
    set @testString = 'This is a long string'
    print @testString

 

Visit the DevX Tip Bank

 





   
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date