October 26, 2010 at 1:29 pm
is there a way for the following to force an error rather than truncation? set ansi warnings was not the answer btw.
declare @temp varchar(10)
set @temp = '12345678901234567'
print @temp
no matter what, it wont error, and I think it should. Is there a way to do this with a database or server setting?
October 26, 2010 at 1:46 pm
it's a behavior thing.
a local variable, when you assign something too big, gets truncated.
however an error will occur if you try to insert/update to a table, which has a more rigid set of rules:
declare @temp varchar(10)
set @temp = '12345678901234567'
print @temp
CREATE TABLE #temp(tempval varchar (10) )
INSERT INTO #temp
SELECT '12345678901234567'
Msg 8152, Level 16, State 14, Line 2
String or binary data would be truncated.
The statement has been terminated.
Lowell
October 26, 2010 at 1:52 pm
I'm aware of the error when trying to go to a table... I was just wondering if I can set something, so that when I try inserting too large a value to a variable, it will error out.(rather than truncation)
October 26, 2010 at 2:59 pm
Not directly.
Where does the value come from when you aren't hard-coding it into a sample for this forum?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply