实用T-SQL代码

1.根据出生日期计算当前已满周岁

DECLARE @birth datetime
SET @birth='1990-01-01'
SELECT (cast(convert(char( 8 ),GETDATE(),112) as int) - cast(convert(char(8),@birth,112) as int))/10000

 

2.COUNT(expression) just returns the total number of rows in which that expression is not null.

COUNT函数返回值不为null的行数。

ID FullName
1 NULL
2 NULL
SELECT COUNT(1) FROM t1 -- Returns 2
SELECT COUNT(FullName) FROM t1 -- Returns 0
COUNT(expression) just returns the total number of rows in which that expression is not null. - See more at: http://www.sqlteam.com/article/how-to-use-group-by-in-sql-server#sthash.b6O058Mg.dpuf

 (持续更新中)

posted @ 2015-01-27 17:08  wsion  阅读(193)  评论(0编辑  收藏  举报