sql笔记

1.根据生日来查年龄

declare @nl datetime, @str varchar(4000)
set @str=''
select top 50 @str =@str++','+ name+':'+convert(nvarchar,DATEDIFF(yy,birthday,getdate())) from BasicData..user_baseinfo where datediff(dd,birthday,getdate()) <>0
select Substring(@str,2,LEN(@str))

 

 

2.查询某个时间

select * from [AppLogs].[dbo].[user_tokens] where '2012-11-05'=CONVERT(varchar(10),createdatetime,120) 

你可能感兴趣的:(sql)