Friday, March 30, 2012

parameter problem in sql2005 sp

in sql2005 store procedure is accepting the varchar value which is more than the parameter's varchar value size it is not giving any exception error but removes the remaining character from right side

Example :

Table

-

create table employee

(Empname Varchar(5), EmpNo Int)

Procedure

create procedure test (@.para1 Varchar(5))

as

SELECT * FROM employee WHRE empNAME=@.PARA1

Execution

--

exec test 'ABCDEFGH'

it consider only 'ABCDE' and ignores remaining character without giving any exception error.

Thanks,

It is the specification. Not only in 2005 earlier versions also use the same specification.

But in sql server 2005 you can overcome this issue using Varchar(max) it never truncate the value.

Declare @.A varchar(1), @.B varchar(Max);

Set @.A = '1234' --Truncated value

Set @.B = '1234' --Never Truncate the value

Select @.A, @.B

Note:

The character length is only validated on Insert & Update statement.

|||thanks fo reply

No comments:

Post a Comment