question

Bhupendra99 avatar image
Bhupendra99 asked

Weired truncation issues

I have an sp named substatus which has an input parameter as AssignTo having length of 10. When I pass a value to AssignTo parameter having length > 10, rather than giving "string or binary data would be truncated" it is truncating the value passed to 10 characters. If we had tried saving more characters in a column of a table then it would have given an error of "string or binary data truncated". Why is the same rule not applicable if we are using variables? Can anyone please explain why it is behaving like this? sp definition ALTER PROC [dbo].[SubStatus] ( @AssignTo VARCHAR(10) = NULL ) AS BEGIN SELECT Case when @AssignTo IN ('Test TEAM','HelpUserDesk') Then 'Internal Team' else @AssignTo End END GO exec SubStatus 'HelpUserDesk'
syntaxtruncate
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
This is known as ***silent truncation*** and is just the way SQL Server works! There's an open Connect item to vote up if you want : https://connect.microsoft.com/SQLServer/feedback/details/622699/stored-procedures-should-throw-error-message-when-called-with-string-values-which-exceed-lenght-of-stored-procedure-parameter
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.