Solved

eturn all results only in the same month

Posted on 2008-06-16
7
216 Views
Last Modified: 2010-03-19
i know i have asked something like this yesterday but  this is a different query

i have a date time stamp in my DB (TIMEDATE)  format is like this 2008-06-01 15:16:00.0
i have a variable passed  called 'datepassed' with a format like this: June 2008

now i need to return all results only in the same month, i have this so far but does not return anything.

       SELECT  TIMEDATE
        FROM orders
        WHERE TIMEDATE  = '#datepassed#'

PS i want to group the returned results by day also
0
Comment
Question by:pigmentarts
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21796403
      SELECT  TIMEDATE
        FROM orders
where timedate >= '6/1/2008' and
timedate < '7/1/2008'
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 21796421
You can do something like this:

SELECT  TIMEDATE
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21796454
But, it will be slow because of the function performed on the field...
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 12

Author Comment

by:pigmentarts
ID: 21796462
emoreau that seems to work perfect.
chapmandew its a dynamic date so  emoreau answer work a little better

ok so now i am getting results like the following i need to group by the day

         June, 01 2008 15:16:00
      
       June, 01 2008 15:38:00
      
       June, 01 2008 16:15:00
      
       June, 01 2008 18:51:00
      
       June, 02 2008 10:03:00
      
       June, 02 2008 11:09:00
      
       June, 02 2008 12:50:00
      
       June, 02 2008 14:16:00
      
       June, 02 2008 17:17:00
      
       June, 03 2008 09:45:00
      
       June, 03 2008 09:51:00
      
       June, 03 2008 10:10:00
0
 
LVL 7

Expert Comment

by:Zippit
ID: 21796482
 SELECT  TIMEDATE
        FROM orders
        WHERE TIMEDATE  BETWEEN ('2008-01-01 00:00:00' and '2008-01-31 23:59:59')
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 21796487
SELECT  distinct CONVERT(VARCHAR(10), TIMEDATE , 120)
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 21796522
emoreau
 that works thanks
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question