Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Stored procedure parameters


Stored procedure parameters

Author
Message
gary.rumble
gary.rumble
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1117 Visits: 1613
Comments posted to this topic are about the item Stored procedure parameters
SuperDBA-207096
SuperDBA-207096
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1479 Visits: 711
Interesting question. Shows the results may not necessarily be what you'd expect.

I've been burnt by this before, good knowlege!
Aaron N. Cutshall
Aaron N. Cutshall
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1600 Visits: 964
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
Slick84
Slick84
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 1163
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.

--
Hehe
Aaron N. Cutshall
Aaron N. Cutshall
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1600 Visits: 964
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
Slick84
Slick84
Mr or Mrs. 500
Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)Mr or Mrs. 500 (500 reputation)

Group: General Forum Members
Points: 500 Visits: 1163
That's correct. I missed that. Thanks!

--
Hehe
Oleg Netchaev
Oleg Netchaev
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 1809
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
myheadhurts
myheadhurts
SSC-Enthusiastic
SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)SSC-Enthusiastic (138 reputation)

Group: General Forum Members
Points: 138 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
john.arnott
john.arnott
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1474 Visits: 3059
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."
Jon Cooney
Jon Cooney
SSC-Enthusiastic
SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)SSC-Enthusiastic (191 reputation)

Group: General Forum Members
Points: 191 Visits: 320
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search