create table tt(id int identity(1,1) ,idx varchar(50)) insert into tt values('a')select @@identity select * from tt /* --------------------------------------- 5(1 行受影响)id idx ----------- -------------------------------------------------- 1 a 2 a 3 a 4 a 5 a(5 行受影响) */
使这个意思吗CREATE PROC GetZhouJi @in_Day as VARCHAR(20) ,@out_zhouji as varchar(10) output as if isdate(@in_Day)=1 select @out_zhouji= case datepart(dw,@in_Day) when 1 then '日曜日' when 2 then '月曜日' when 3 then '火曜日' when 4 then '水曜日' when 5 then '木曜日' when 6 then '金曜日' when 7 then '土曜日' end else select @out_zhouji='ERROR' godeclare @s as varchar(10) exec GetZhouJi '1985-07/20',@s output select @s /*---------- 土曜日(1 行受影响) */
各位...小弟是想得到刚插入那条记录的主键的值难道是这样 int i = INSERT INTO Friends(playerid,nickname,targetid,type,state) VALUES(33, '222', 55, 2, 200 ) select @@identity 这样返回的是受影响的函数...
写一个存储过程,包含一个输出的参数。 create procedure ab(@maxid int output) as insert into ..... select @maxid=@@identity然后调用存储过程: declare @i int set @i=0 ab @i 不过我不知道如果同时多人插入数据,获得的@@identity还是否准确。所以对于要得到@@identity的插入操作,我都是在客户端程序里写的。
insert into tt values('a')select @@identity
select * from tt
/*
---------------------------------------
5(1 行受影响)id idx
----------- --------------------------------------------------
1 a
2 a
3 a
4 a
5 a(5 行受影响)
*/
自动递增列是不能插入的,
select @@identity 是得到自动递增列的最新值查询主键列
sp_pkeys 表名
;
select @@identity加个分号试试
这东西应该对你有用。
@in_Day as VARCHAR(20)
,@out_zhouji as varchar(10) output
as
if isdate(@in_Day)=1
select @out_zhouji=
case datepart(dw,@in_Day)
when 1 then '日曜日'
when 2 then '月曜日'
when 3 then '火曜日'
when 4 then '水曜日'
when 5 then '木曜日'
when 6 then '金曜日'
when 7 then '土曜日'
end
else
select @out_zhouji='ERROR'
godeclare @s as varchar(10) exec GetZhouJi '1985-07/20',@s output select @s
/*----------
土曜日(1 行受影响)
*/
select @I=@@identity SELECT @I
create procedure ab(@maxid int output) as
insert into .....
select @maxid=@@identity然后调用存储过程:
declare @i int
set @i=0
ab @i
不过我不知道如果同时多人插入数据,获得的@@identity还是否准确。所以对于要得到@@identity的插入操作,我都是在客户端程序里写的。