日期:2014-05-19  浏览次数:20505 次

哪位大侠告诉我,到底这个存储过程该怎么改啊!!!
小弟写了个存储过程,
可执行的时候总是报错,
哪位大侠仁慈一下,帮忙给改一下啊.
谢谢了啊!!!!


create   proc   useradd
(
@user_name   varchar(20),
@user_pwd   varchar(20),
@object_id   varchar(8),
@user_power   char(1)
)as
(   declare   @@uid   int  
set   @uid=0
SELECT   TOP   1   @uid=user_id
                FROM   tcm_user
order   by   user_id   desc
@uid=@uid+1
select   user_id   from   tcm_user  
insert   tcm_user
(user_name,user_pwd,object_id,user_power)
values
(@user_name,@user_pwd,@object_id+str(@uid),@user_power)
)

------解决方案--------------------
try

create proc useradd
(
@user_name varchar(20),
@user_pwd varchar(20),
@object_id varchar(8),
@user_power char(1)
)as
(
insert tcm_user
([user_name],user_pwd,[object_id],user_power)
select TOP 1
@user_name,@user_pwd,@object_id+Rtrim([user_id] + 1), @user_power
FROM tcm_user
order by user_id desc
)
------解决方案--------------------
create proc useradd
(
@user_name varchar(20),
@user_pwd varchar(20),
@object_id varchar(8),
@user_power char(1)
)as
( declare @uid int
set @uid=0
SELECT TOP 1 @uid=user_id
FROM tcm_user
order by user_id desc
SET @uid=@uid+1
select user_id from tcm_user
insert tcm_user
(user_name,user_pwd,object_id,user_power)
values
(@user_name,@user_pwd,@object_id+str(@uid),@user_power)
)

------解决方案--------------------
alter proc useradd
@user_name varchar(20),
@user_pwd varchar(20),
@object_id varchar(8),
@user_power char(1)
as
declare @uid int
set @uid=0
SELECT TOP 1 @uid=user_id FROM tcm_user order by user_id desc

set @uid=@uid+1

select user_id from tcm_user

insert tcm_user
(user_id , user_name , user_pwd , object_id , user_power)
values
(@uid , @user_name , @user_pwd , @object_id + str(@uid) , @user_power)

另外,@object_id + str(@uid),会造成“将截断字符串或二进制数据。语句已终止。”的错误,是你object_id字段太小的原因