Problem with query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asivakrupa
    New Member
    • Apr 2009
    • 14

    Problem with query

    Hi,

    I need a query in SQL Sever which will select the records based on the date of creation.The query is,

    List the opportunity name where the date of creation is before 3 weeks.

    I do not know to create a SQL query for this. Pls do help me out with this.
    Thanks in advance.
    Sivakrupa Arulmani.
  • Uncle Dickie
    New Member
    • Nov 2008
    • 67

    #2
    Assuming your table has a DateCreated (or equivalent name) column then it should be a simple WHERE statement:

    Code:
    SELECT *
    FROM table
    WHERE DateCreated < DATEADD(dd,-21,getdate())
    If there is no DateCreated column you will probably need to add one and use a trigger to populate it when a record is added (or something similar).

    Comment

    • sujitkar
      New Member
      • Mar 2009
      • 7

      #3
      Hi friends,
      I dont know where to post this query....so I am posting it here. Hope you guys will help me. I am using SQL Server 2005. Everything seems to be alright there. But the following Left Outer Join Query does not give the desired result.

      SELECT m.meter_addr, r.Date, r.Reading
      FROM meter_table AS m LEFT OUTER JOIN
      WebSite_Support .dbo.Readings AS r ON m.meter_addr = r.meter_ID

      the table m contains 210 records
      the table r contains 207 records

      But the above query returns only 207 records. According to me it should have returned 210 records. Please Help. Thanx in advance.

      Comment

      • pankajvtcse
        New Member
        • Jul 2009
        • 10

        #4
        YOu are using left outer join ,so you need to put your first (table from which you want to take data) on left side of join.

        SELECT m.meter_addr, r.Date, r.Reading
        FROM WebSite_Support .dbo.Readings AS r
        LEFT OUTER JOIN
        meter_table AS m
        ON m.meter_addr = r.meter_ID
        Hope this will help you.

        -Pankaj Tambe

        Comment

        • BhumikaNT
          New Member
          • Jul 2009
          • 5

          #5
          Dear Sujitkar

          R u using where condition in your Query??? And that too on table r???

          As your join Query seems fine.

          Regards,

          Comment

          Working...