SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


problem with stored procedure


problem with stored procedure

Author
Message
yennhi2812
yennhi2812
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 6
I have a table

Create table SINHVIEN (
MASV nvarchar(20) not null,
HOTEN nvarchar(100) not null,
NGAYSINH datetime,
DIACHI nvarchar(200),
MALOP varchar(20),
TENDN nvarchar(100) not null,
MATKHAU varbinary not null,
constraint PK_SINHVIEN primary key (MASV)
)
go


and I want to create a stored procedure to insert values for this table in security by use md5 hash function.

CREATE PROCEDURE SP_INS_SINHVIEN
@MASV nvarchar(20),
@HOTEN nvarchar(100),
@NGAYSINH datetime,
@DIACHI nvarchar(200),
@MALOP varchar(20),
@TENDN nvarchar(100),
@MATKHAU varchar(100)
AS
INSERT INTO SINHVIEN
VALUES
(
@MASV,
@HOTEN,
@NGAYSINH,
@DIACHI,
@MALOP,
@TENDN,
HASHBYTES('MD5',@MATKHAU)
)
GO


but when I try to execute this stored procedure,


insert into SINHVIEN values ( '1012283','Vo Thi Yen Nhi', '01/01/1992', 'VietNam', 'TH2010/4', 'meomun', HashBytes('MD5', '123456'))


I get error


Msg 8152, Level 16, State 11, Line 1
String or binary data would be truncated.
The statement has been terminated.


I debug and know the problem is HashBytes('MD5', '123456')
how can I do to fix this problem?
Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10406 Visits: 5157
Hi,

Change table:

alter table SINHVIEN
alter column MATKHAU varbinary(max) not null



Change SP:

Alter PROCEDURE SP_INS_SINHVIEN
@MASV nvarchar(20),
@HOTEN nvarchar(100),
@NGAYSINH datetime,
@DIACHI nvarchar(200),
@MALOP varchar(20),
@TENDN nvarchar(100),
@MATKHAU varchar(8000)
AS
INSERT INTO SINHVIEN
VALUES
(
@MASV,
@HOTEN,
@NGAYSINH,
@DIACHI,
@MALOP,
@TENDN,
convert(varbinary(max),HASHBYTES('MD5',@MATKHAU))
)
GO



Regards
IgorMi

Igor Micev,
My blog: www.igormicev.com
yennhi2812
yennhi2812
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 6
Thank you so much!
Send from VietNam!
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