`
felixsky
  • 浏览: 7490 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类

SQL to retrieve First/last day of a specific day

sql 
阅读更多

最近做的数据ETL经常需要计算给定日期的月份第一天或者是最后一天之类的问题。Sql server提供了类似DateAdd, Datepart 以及DateDiff 之类的函数供使用。为了方便以后在遇到类似的需求,在这里做个记录,方便自己查找。

 

First day of month:

select dateadd(day,1-DATEPART(day,getdate()),getdate())

 思路: 获取当前日期的天数,然后用现在的日期减去日期的天数加1便是月份的第一天了。

同样的思路:

Last day of month:

select dateadd(month, 1,dateadd(day,-DATEPART(day,getdate()),getdate()))

权且做个记录。

 

 

分享到:
评论
2 楼 tjj006 2014-10-15  
 
1 楼 tjj006 2014-05-09  
 

相关推荐

    The Language of SQL(Addison,2ed,2016)

    For SQL beginners, it’s more important for a book to focus on general concepts and to offer clear explanations and examples of what various SQL statements can accomplish. This is that book. A number ...

    The.Language.of.SQL.2nd.Edition.0134658256

    For SQL beginners, it’s more important for a book to focus on general concepts and to offer clear explanations and examples of what various SQL statements can accomplish. This is that book. A number...

    SQL: A BEGINNER'S GUIDE 3/E

    Key Skills & Concepts--Lists of specific skills covered in the chapter Ask the Experts--Q&A sections filled with bonus information and helpful tips Try This--Hands-on exercises that show how to apply ...

    微软内部资料-SQL性能优化5

    Just as the organization of a telephone directory makes it easy for a person to search, SQL Server quickly searches a table with a clustered index. Because a clustered index determines the sequence ...

    Beginning T-SQL with Microsoft SQL Server 2005 and 2008

    Transact-SQL, or T-SQL, is Microsoft Corporation’s powerful implementation of the ANSI standard SQL database query language, which was designed to retrieve, manipulate, and add data to relational ...

    SSD7 选择题。Multiple-Choice

    Which of the following SQL statements can be used to add a row to a table? (a) CREATE (b) INSERT (c) APPEND (d) ADD Correct answer is (b) Your score on this question is: 10.00 ...

    报错ORA01804解决方法.txt

    使用PL/SQL登录ORACLE数据 报错,error while trying to retrieve text for error ORA-01804,的解决方法,操作步骤,在windows server 2008R2 64位,oracle 12C,PLSQL Developer 12 64位,以上使用环境正常,

    This module demostrates how to retrieve information about a

    This module demostrates how to retrieve information about a joystick. This is a great module for game programmers.

    解决Oracle11g,PL/SQL连接报错问题

    解决Oracle11g,PL/SQL连接报错问题 解压 解压instantclient-basic-nt-11.2.0.2.0.zip,例如到D:\instantclient_11_2 3、设置PLSQL Developer 启动PLSQL Developer,不登录点取消进入PLSQL Developer,Tools->>...

    Oracle Database 10g PL-SQL Programming

    By covering these topics, "Oracle Database 10g PL/SQL Programming" provides a comprehensive guide for developers looking to leverage the power of PL/SQL within the Oracle database environment....

    ADS1220源码 MSP430单片机ADS1220驱动源代码.zip

    ADS1220源码 MSP430单片机ADS1220驱动源代码: void ADS1220Init(void) { P3SEL |= ADS1220_DIN +... // and should be used as an interrupt to retrieve data // define outputs P1DIR |= ADS1220_CS; r

    Begining SQL

    Paul Wilton is a successful Wrox "Beginning" book author and is an ideal author to write for those who want a firm grasp of standard SQL before learning the details specific to a particular database ...

    an introduction to information retrieve

    标题为“an introduction to information retrieve”的文档,实际上是指《信息检索导论》这本书的介绍。该书由斯坦福大学出版,作者包括 Christopher D. Manning、Prabhakar Raghavan 和 Hinrich Schütze。根据描述...

    This demonstrates how to retrieve the file size from a speci

    描述中提到,“This demonstrates how to retrieve the file size from a specified file”,这提示我们关注的是一个实际的代码示例或者教程,它将展示如何从给定的文件路径中获取文件的大小信息。这通常涉及到读取...

    计算机网络第六版答案

    12. A circuit-switched network can guarantee a certain amount of end-to-end bandwidth for the duration of a call. Most packet-switched networks today (including the Internet) cannot make any end-to-...

    Sybex - Mastering Visual Basic .NET Transact SQL (VBL).pdf

    In Chapter 20, you builtSQL statements to retrieve and update rows in a database. You also learned all the variations of the SELECT statement. Some restrictions, however, can’t be expressed with a ...

    HP_Vertica_7.1.x_SQL_Reference_Manual

    They provide a way to group multiple SQL statements into a single unit of work that can be committed or rolled back as a whole. This feature is crucial for maintaining data integrity in scenarios ...

    VC_code_SQL_string_retrieve_classical_condition.ra_vc 检索

    VC开发SQL 字符串检索条件经典代码VC + + code in SQL string to retrieve the classical condition

    SAS.9.2.SQL.Procedure.Users.Guide

    In conclusion, the SAS 9.2 SQL Procedure User's Guide covers a comprehensive range of topics related to using PROC SQL effectively. From retrieving data from single tables to creating and updating ...

Global site tag (gtag.js) - Google Analytics