Solved

eturn all results only in the same month

Posted on 2008-06-16
7
230 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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