Question : Using GetDate function to ruturn results

Hello all,

I am trying to run a select statement that returns the results where a specified date field is from the last 7 or 30 days. So far my query looks like below.


SELECT top 25 sh.No_, sh.[Sell-to Customer No_], sh.[Bill-to Name], sh.[Due Date],

sh.[Salesperson Code], sh.[Document Date],
 sh.[Expiration Date], sh.[Quoted By], sh.[Status], c.[E-Mail]
FROM [AB50LIVE].[dbo].[AB Live$Sales Header] AS sh
INNER JOIN dbo.[AB Live$Customer] AS c
ON sh.[Sell-to Customer No_]=c.[No_]
Where c.[E-Mail] <> ' ';

The sh.[Due Date] field is the column which I would need to get results of the last 7 or 30 days. I was thinking of using the GetDate function but so far my attempts have not been successfully at plugging it in. Any assistance would be appreciated. Thanks.

Keith

Answer : Using GetDate function to ruturn results

try
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
SELECT top 25 
		sh.No_, 
		sh.[Sell-to Customer No_], 
		sh.[Bill-to Name], 
		sh.[Due Date],
		sh.[Salesperson Code], 
		sh.[Document Date],
		sh.[Expiration Date], 
		sh.[Quoted By], 
		sh.[Status], 
		c.[E-Mail]
FROM 
	[AB50LIVE].[dbo].[AB Live$Sales Header] AS sh
	INNER JOIN dbo.[AB Live$Customer] AS c ON sh.[Sell-to Customer No_]=c.[No_]
Where 
	c.[E-Mail] <> ' '
	and sh.[Due Date] between GETDATE()-7 and GETDATE()
Random Solutions  
 
programming4us programming4us