Solved

eturn all results only in the same month

Posted on 2008-06-16
7
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

749 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