精确求几岁到几岁的问题,谁能吧这段代码简化下了 子查询select * from (select a,b,c, d=表达式 from tb ...) where d between ... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table tb(出生年月 datetime)insert into tb values('1930-01-01')insert into tb values('1980-12-31')insert into tb values('1960-07-01')insert into tb values('1969-12-07')insert into tb values('2000-12-06')insert into tb values('2000-12-08')goselect * , nl = case when right(convert(varchar(10),出生年月,120),5) >= right(convert(varchar(10),getdate(),120),5) then datediff(yy,出生年月,getdate()) -1 else datediff(yy,出生年月,getdate()) endfrom tbdrop table tb/*出生年月 nl ------------------------------------------------------ ----------- 1930-01-01 00:00:00.000 791980-12-31 00:00:00.000 281960-07-01 00:00:00.000 491969-12-07 00:00:00.000 392000-12-06 00:00:00.000 92000-12-08 00:00:00.000 8(所影响的行数为 6 行)*/ 我觉得从效率来看的话,并没问题若觉得代码太多的话!我觉得可以考虑写个自定义函数。。create function ....return 关于多表查询执行顺序的问题请教 |zyciis| 江湖救急 请大家帮贴一个没有主键的分页存储过程 谢谢 急 如下SQL应该怎么写 新闻数据无法写入,在线求助中 初学mssql。一个有关存储过程的问题 百思不得其解的分组问题. 关于SQL数据库的问题,谢谢! 急!!! 请问如何让更新触发器得到更新行的主键? 多对多无中间表转换成多对多有中间表 计算每笔记录余额,请问这条存储过程哪有问题呢? 求教帖:CHARINDEX真的比LIKE快吗?
insert into tb values('1930-01-01')
insert into tb values('1980-12-31')
insert into tb values('1960-07-01')
insert into tb values('1969-12-07')
insert into tb values('2000-12-06')
insert into tb values('2000-12-08')
goselect * , nl =
case when right(convert(varchar(10),出生年月,120),5) >= right(convert(varchar(10),getdate(),120),5) then datediff(yy,出生年月,getdate()) -1
else datediff(yy,出生年月,getdate())
end
from tbdrop table tb/*
出生年月 nl
------------------------------------------------------ -----------
1930-01-01 00:00:00.000 79
1980-12-31 00:00:00.000 28
1960-07-01 00:00:00.000 49
1969-12-07 00:00:00.000 39
2000-12-06 00:00:00.000 9
2000-12-08 00:00:00.000 8(所影响的行数为 6 行)
*/