sql高级查询插入数据于存储过程
我想创建一个存储过程
if exists (select * from sysobjects where name = 'usp_cardid')
drop proc usp_cardid
go
create proc usp_cardid
@i int output,
@j int output
as
set @j = 10103576
select @i = RAND((DATEPART(MM , GETDATE()) * 100000) + (DATEPART(SS , GETDATE()) * 1000) + DATEPART(MS , GETDATE())) * 10000000
print convert(varchar(20) , @j) + convert(varchar(20) , @i)
go
declare @i int
declare @j int
exec usp_cardid @i output , @j output
这个结果给我创建的一个表做主键
我想在添加数据时用
insert into CardInfo values((declare @i int declare @j int exec usp_cardid @i output , @j output),'RMB','活期','','1','1','000000','','1')
添加到表里去,但是不能成功!
希望朋友们帮我解决这个问题
[解决办法]
1.存储过程不能返回两个值.
2.存储过程中不要使用getdate(),使用变量传进去.
3.你这是想获取到存储过程的值?然后插入到表中去?
create proc usp_cardid @dt datetime , @s varchar(100) output
as
begin
declare @i as int
declare @j as int
set @j = 10103576
select @i = RAND((DATEPART(MM , @dt) * 100000) + (DATEPART(SS , @dt) * 1000) + DATEPART(MS , @dt)) * 10000000
print convert(varchar(20) , @j) + convert(varchar(20) , @i)
set @s = cast(@i as varchar) + ',' + cast(@j as varchar)
end
go
declare @i int
declare @j int
declare @dt datetime
declare @s varchar(100)
set @dt = getdate()
exec usp_cardid @dt , @s output
set @i = cast(left(@s , charindex(',',@s) - 1) as int)
set @j = cast(substring(@s , charindex(',',@s) + 1 , len(@s)) as int)
insert into CardInfo values(@i,@j ,'RMB','活期','','1','1','000000','','1')