Solved

eturn all results only in the same month

Posted on 2008-06-16
7
241 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

627 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