|
Posted by John Bokma on 03/02/06 10:17
Erland Sommarskog <esquel@sommarskog.se> wrote:
> John Bokma (john@castleamber.com) writes:
>> Erland Sommarskog <esquel@sommarskog.se> wrote:
>>> John Bokma (john@castleamber.com) writes:
>>>> "String or binary data would be truncated"
>>>> Can MS SQL automatically do the truncation?
>>>
>>> Yes, if you issue the command SET ANSI_WARNINGS OFF.
>>>
>>> However, this is not really recommendable, as there are
>>> functionality in SQL Server that requires ANSI_WARNINGS to be on.
>>>
>>> So you are better off by truncating the data yourself, for instance
>>> with cast or convert. Or bounce thata over a variable. SQL Server
>>> does not complain if you assign a variable with an overlong value.
>>
>> Thanks. Is there an easy way to insert and truncate the data via SQL
>> in one go (or give something like an "It's ok to truncate hint"? I
>> don't want to hardcode the max length of a text column (for example)
>> in the program code.
>
> See above about SET ANSI_WARNINGS. That's the hint you are looking
> for. But also beware of the caveat.
I was somehow thinking on SET ANSI_WARNINGS OFF, query, back on, but
indeed, need to read the problems this might cause. I was hoping that
there would be an easier option (well, maybe it's easy enough :-) )
Thanks,
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Navigation:
[Reply to this message]
|