选择从月初到当前日期的记录 [英] Select records from start of month to current date

查看:90
本文介绍了选择从月初到当前日期的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择在当月初和当日之间添加到数据库中的记录-我或多或少知道如何从当日以及特定时间段内获取记录-但如何获取它,使其从当前日历月的月初开始?

I'm trying to select records that were added to the database between the start of the current month and the current day - I more or less know how to get records from the current day, and within a specific time period - but how do I get it so it starts from the beginning of the current calendar month?

推荐答案

DECLARE @sm DATETIME;
SET @sm = DATEADD(DAY, 1-DAY(GETDATE()), DATEDIFF(DAY, 0, GETDATE()));

SELECT columns 
    FROM dbo.foo 
    WHERE datetime_column >= @sm;

这篇关于选择从月初到当前日期的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆