Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Stored procedure parameters Expand / Collapse
Author
Message
Posted Saturday, August 8, 2009 4:56 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 3:40 PM
Points: 850, Visits: 1,309
Comments posted to this topic are about the item Stored procedure parameters
Post #767453
Posted Monday, August 10, 2009 4:31 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Wednesday, January 2, 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!
Post #767731
Posted Monday, August 10, 2009 6:40 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 22, 2014 11:25 AM
Points: 1,144, Visits: 546
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
Post #767800
Posted Monday, August 10, 2009 6:49 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-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.

--
Post #767811
Posted Monday, August 10, 2009 6:56 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 22, 2014 11:25 AM
Points: 1,144, Visits: 546
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
Post #767815
Posted Monday, August 10, 2009 7:02 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-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!

--
Post #767818
Posted Monday, August 10, 2009 9:19 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, October 23, 2014 11:58 AM
Points: 1,676, Visits: 1,758
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
Post #767950
Posted Monday, August 10, 2009 10:26 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 1:41 PM
Points: 136, Visits: 635
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
Post #767987
Posted Monday, August 10, 2009 6:35 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 28, 2014 8:53 PM
Points: 1,388, Visits: 3,039
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."
Post #768301
Posted Thursday, August 13, 2009 9:26 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 24, 2014 6:01 AM
Points: 191, Visits: 317
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.
Post #770263
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse