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

亲人们啊,帮忙解决一下吧,急啊.
小弟写了个存储过程,
可执行的时候总是报错,
哪位大侠仁慈一下,帮忙给改一下啊.
谢谢了啊!!!!

tcm_user表里有5个字段,user_id(int类型),user_name,user_pwd,obj_id,user_power(都是varchar类型)
其中user_id是自动增长列,
存储过程的目的,是向tcm_user表添加一行,
其中obj_id字段的记录,是传入参object_id的值,加上(user_id+1)的值.

create   proc   useradd
(
@user_name   varchar(20),
@user_pwd   varchar(20),
@object_id   varchar(20),
@user_power   char(1)
)as
(   declare   @obj   int  
set   @obj=0
SELECT   TOP   1   @obj=user_id
                FROM   tcm_user
order   by   user_id   desc
SET   @obj=@obj+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(@obj),@user_power)
)

各位高手之高手之高高手,帮忙给改改吧!!!!

------解决方案--------------------
按照搂主的内容,创建了表(tb_test)及存储过程(useradd)
执行后没有问题啊。

存储过程:
CREATE proc useradd
(
@user_name varchar(20),
@user_pwd varchar(20),
@object_id varchar(20),
@user_power char(1)
)as

declare @obj int
set @obj=0
SELECT TOP 1 @obj=user_id FROM tb_test order by user_id desc
SET @obj=@obj+1
select user_id from tb_test
insert tb_test (user_name,user_pwd,obj_id,user_power)
values (@user_name,@user_pwd,@object_id + str(@obj),@user_power)


查询分析器中的执行语句:
declare @user_name varchar(20)
declare @user_pwd varchar(20)
declare @object_id varchar(20)
declare @user_power char(1)
select @user_name = 'lee ',@user_pwd= '111 ',@object_id= '123 ',@user_power= 'f '
exec useradd @user_name ,@user_pwd ,@object_id ,@user_power

环境:
MS Sql Server 2000 + sp4