mrledbet


Why does SQL Server truncate the data being stuffed into "@vt" without throwing some kind of error or warning The print statement puts "123456" into the output window.

Believe it or not .. our development team is actually trying to use this minor issue as justification for going with Oracle on this project, because they deem this as a data integrity issue and PL/SQL does throw an error. They would prefer to have an error thrown, instead of just silently truncating the data.

declare @vt varchar(6)

select @vt = '12345678'

print @vt

Is there a way that I can get T-SQL to throw an error or warning when this occurs I thought a UDT with a rule applied to it might do the trick, but that hasn't worked for some reason.

Or any other creative solutions that you can think of

Thank you, Mark




Re: T-SQL / varchar truncate solutions

WesleyB


First of all this would fail if it was an INSERT or UPDATE with the error "String or binary data would be

truncated".

The Books Online state:

"ANSI_WARNINGS is not honored when passing parameters in a stored procedure, user-defined function,

or when declaring and setting variables in a batch statement. For example, if a variable is defined as

char(3), and then set to a value larger than three characters, the data is truncated to the defined size and the

INSERT or UPDATE statement succeeds."

I would rather have an architecture that prevents this situation from happening instead of choosing my

database vendor based on this minor issue.

There are a million reasons to choose for a specific database product and I find it hard to comprehend that

this would be THE reason for choosing a specific database vendor.

WesleyB

Visit my SQL Server weblog @ http://dis4ea.blogspot.com