sql - How can I use GETDATE() to get month and year from the past month? -


How can I get a statement that can get me last month and this year?

I enter one INSERT and one column report_date in [datetime]

  table_A (report_data) values ​​(??);   

I want to show this last month and year, for example today is 4/21/2014, so it will show 3/2014 in the column if today was May 1, 2014, Show 4 / 2014? Is it possible or should it be his day?

You are looking for function:

  SELECT DATEPART ( Month, DATEADD (month, -1, GETDATE ()), DATEPART (year, DATEADD (month, -1, GETDATE ())    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -