By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,574 Members | 1,968 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,574 IT Pros & Developers. It's quick & easy.

Problem with query

P: 14
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.
Apr 8 '09 #1
Share this Question
Share on Google+
4 Replies


Uncle Dickie
P: 67
Assuming your table has a DateCreated (or equivalent name) column then it should be a simple WHERE statement:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM table
  3. 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).
Apr 9 '09 #2

P: 7
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.
Apr 13 '09 #3

P: 10
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
Jul 17 '09 #4

P: 5
Dear Sujitkar

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

As your join Query seems fine.

Regards,
Jul 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.