修改一下
select isnull(max(这个字段),convert(varchar(10),getdate(),112) + '-00') from yourtable where case when left(这个字段 ,charindex('-',这个字段 )-1)=convert(varchar(10),getdate(),112)
select convert(char(8),getdate(),112)+right('0'+rtrim(isnull(max(replace(convert(char(8),getdate(),112)+'-',字段,'')),0)+1),2) 结果 from 表 where 字段 like convert(char(8),getdate(),112)+'%'
select isnull(max(这个字段),convert(varchar(10),getdate(),112) + '-01') from yourtable where case when left(这个字段 ,charindex('-',这个字段 )-1)=convert(varchar(10),getdate(),112)
1。最后记录的关键字是最大的:
select max(关键字) from table1
2。关键字不是最大的,若有日期时间字段,取日期时间字段最大的关键字:
select 关键字 from table1 where 日期时间 = (select max(日期时间) from table1)
3。若不是前两个,就比较麻烦了,要用临时表。
select *, identity(int,1,1) id into #t from table1
select 关键字 from table1 where id = (select max(id) from table1)