如何取得SQL存储过程中的参数值?谢谢!
create table keyTable(
[year] int,--年
keyValue int--id值
)
--插入年和初始id值
insert into keyTable select 2012,0 union all select 2013,0
--先将Id值+1,再取出来
create proc sp_getKey
@id VARCHAR(12) OUTPUT
AS
BEGIN
declare @keyValue int
update keyTable set keyValue=keyValue+1 where [year]=year(GETDATE())
select @keyValue=keyValue from keyTable where [year]=year(GETDATE())
set @id='QXD' + cast(year(GETDATE()) as varchar) + RIGHT('00000' + cast(@keyValue as varchar),5)
end
--测试
DECLARE @id VARCHAR(12)
EXEC sp_getKey @id OUTPUT
PRINT @id
-----------
(1 行受影响)
QXD201200060
我有条INSERT插入语句中想使用这个@id的值,不懂应该如何取得呢?谢谢! With Cmd
.ActiveConnection = Conn
.CommandType = adCmdStoredProc
.......
debug.print Cmd(0)--返回值
end with
你好,我按如下代码运行后提示:实时错误'-2147217887(80040e21)'
[Microsoft][ODBC SQL Server Driver]没有执行可选特性
Dim comm As New ADODB.Command
comm.ActiveConnection = "DSN=OVERTIME;UID=sa;PWD=sdb@680858"
comm.CommandType = adCmdStoredProc
comm.CommandText = "DECLARE @id VARCHAR(14) exec sp_getKey @id OUTPUT"
Set parIn = comm.CreateParameter("@id", adDate, adParamInput, , 0)
comm.Parameters.Append parIn
comm.Execute
MsgBox comm(0)
请高手帮帮忙,谢谢!
补充:VB , 数据库(包含打印,安装,报表)