|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 3:07 PM
Points: 648,
Visits: 1,050
|
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, January 02, 2013 12:15 PM
Points: 1,443,
Visits: 711
|
|
Interesting question. Shows the results may not necessarily be what you'd expect.
I've been burnt by this before, good knowlege!
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 9:57 AM
Points: 895,
Visits: 504
|
|
I've been burnt by this "feature" too often to not recognize it! It took me hours to track down an issue cause by a string truncation that was being passed as a parameter to an SP. Increasing the parameter size was all it took to fix it.
Time spent tracking down the problem: 6.5 hours Time spent actually fixing the problem: 5 seconds
"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, October 31, 2011 1:10 PM
Points: 480,
Visits: 1,163
|
|
So...why exactly is this happening? I thought the whole 'This is a test string' without the quotes would show up in my result-set.
--
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 9:57 AM
Points: 895,
Visits: 504
|
|
Slick84 (8/10/2009) So...why exactly is this happening? I thought the whole 'This is a test string' without the quotes would show up in my result-set.If you'll notice, the parameter to the SP is limited to a length of 4 characters. Therefore, the value passed in gets truncated to a maximum length of 4 characters without any warning or notice. It can cause some nasty side-affects if something down the road is dependent upon that parameter.
"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, October 31, 2011 1:10 PM
Points: 480,
Visits: 1,163
|
|
That's correct. I missed that. Thanks!
--
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 10:53 AM
Points: 1,662,
Visits: 1,709
|
|
Aaron N. Cutshall (8/10/2009) I've been burnt by this "feature" too often to not recognize it! It took me hours to track down an issue cause by a string truncation that was being passed as a parameter to an SP. Increasing the parameter size was all it took to fix it.
Time spent tracking down the problem: 6.5 hours Time spent actually fixing the problem: 5 seconds It can get even more interesting (and fun to debug) if the value of the parameter can be evaluated by the engine to one of the numeric data types, such as int. Then you can get a * as a result of the procedure execution. For example,
create proc dbo.testProc @testVar varchar(4) as select @testVar GO exec testProc 123456 GO The result of the above is (with results to text option)
---- *
(1 row(s) affected)
While this behavior is by design, it still is a very nice curve ball 
Oleg
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, January 04, 2013 12:17 PM
Points: 135,
Visits: 608
|
|
Explanation: Stored procedure calls will silently truncate strings. I believe the Explanation here is more fundamental than "Stored procedure calls...", instead having to do simply with the declaration of the var. Note that this likewise returns just 4 chars:
declare @testVar varchar(4) set @testVar = 'This is a test string' select @testVar
-MarkO
"You do not really understand something until you can explain it to your grandmother" - Albert Einstein
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
Aaron N. Cutshall (8/10/2009)
Time spent tracking down the problem: 6.5 hours Time spent actually fixing the problem: 5 seconds This reminds me of the story about a field engineer being called in to fix an HVAC (Heating, Ventilation, Air Conditioning) control system for a large building after the on-site guys couldn't make it work. She walks in. Looks at the controls. Re-positions three knobs and hits the restart button. When the building manager looks at the invoice for the call and says "how can you justify $500 just for turning three knobs?", the FE replies "I should have broken that down. It was $10 for turning the knobs, and $490 for knowing which knobs and how far to turn them."
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, April 18, 2013 2:37 AM
Points: 191,
Visits: 307
|
|
This is a cheeky one.
Technet (link) says the following:
The data type of a parameter determines the type and range of values that are accepted for the parameter. For example, if you define a parameter with a tinyint data type, only numeric values ranging from 0 to 255 are accepted. An error is returned if a stored procedure is executed with a value incompatible with the data type.
You would ASSUME 'range of values' implies string length here. Obviously it doesn't.
|
|
|
|