sql server - SQL YEAR(GETDATE()) -


I am currently working on a query that returns the record from within the date range, ideally from the beginning of 2015 Ideal for some date is something in theory, each of the three SET statements given below should not set the variable by 2015?

  DECLARE @startDate datetime; SET @startDate = '20150101'; SET @startDate = YEAR (GETDATE ()); SET @startDate = DATEPART (yyyy, GETDATE ());  

Only for the first time, the hardcode date behaves as expected, the other two return all the records that are being asked by me, am I missing something here?

* Edit: I apologize for how I knew clearly about that, in fact, set to @startDate on 01-01-XXXX Should, where XXXX is anything, is a part of today's date. It is being compared with the second DATETIME variable I hope that clarifies things.

The answer to your question is "no". Variable @StartDate is not a date time:

  set @startDate = 2015  

this does not make sense . An integer that looks like a year is not a date.

If you want the first day of the year, you can do this:

  set @startDate = dateadd (day, 1 - datapester (dooffier, dot data ( ), Cast (as a date)) FirstDeveloper  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -