请问这个存储过程怎么写????(初学者)

Brand1 2002-03-11 02:47:13
我又一个SQL语句,不知道怎么吧她编程存储过程
先取得ID字段的最大值
Select max(ID) from table;
然后将ID转换成数值
Int(ID)


请问这个存储过程怎么写。
...全文
69 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuzhichao 2002-03-11
  • 打赏
  • 举报
回复
去看:

http://www.csdn.net/expert/topic/443/443157.xml
Brand1 2002-03-11
  • 打赏
  • 举报
回复
我这样写怎么也不能通过:
create procedure InsertToTable(
@Tables char(25) ='JBXX',
@KeyFields char(25) = 'ID',
@MaxFields char(25) output
)
declear @IIII int;

select @MaxFields = Max(@KeyFields) from +@Tables
set @IIII = INT(MaxField)
set @MaxField = STR(@IIII+1)
insert into @Tables (@KeyFields) values (@MaxFields)

warning 2002-03-11
  • 打赏
  • 举报
回复
那就再加两个参数,然后用动态sql
warning 2002-03-11
  • 打赏
  • 举报
回复
只要ID中没有字符就可以转换
Brand1 2002-03-11
  • 打赏
  • 举报
回复
如果表名,字段等都变成参数该怎么办呢
Brand1 2002-03-11
  • 打赏
  • 举报
回复
不好意思,我的表中的ID的类型是char的
supsuccess 2002-03-11
  • 打赏
  • 举报
回复
create procedure proc1 @intId int output
as
select @intID=cast((select max(id) from table) as int)
print @intid
go
declare @intid int
exec proc1 @intid output
go
warning 2002-03-11
  • 打赏
  • 举报
回复
create procedure proc1 @intId int output
as
select @intID=convert(int, (select max(id) from table))
warning 2002-03-11
  • 打赏
  • 举报
回复
create procedure proc1
as
declare @intId int
select @intId=max(id) from table
print @intId

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧