Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Queary for Last 15 Days and Last 5 Years

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2010-07-21 : 01:11:08
Dear All,

I am having following queary, in that queary i want last 15 days record and last 5 years record in separate separate queary.

SELECT RD.COLLECTEDDEPOSITID,RD.DATEID,DT.FULL_DATE,RD.ADMISSIONDEPOSIT,RD.DEPOSITBILLING,
RD.INTERIMCOLLECTION,RD.SURGERYDEPOSIT,RD.PACKAGEREVENUE
FROM SA.A_REVENUECOLLECTED_DEPOSIT RD
INNER JOIN D_DATE DT ON RD.DATEID = DT.DATE_ID

So can anybody help me how to do it. Means wat condition i have to give in where clause.


Thanks and Regard's
Harish Patil

sql-programmers
Posting Yak Master

190 Posts

Posted - 2010-07-21 : 01:19:30
I assume DT.Date_ID column is date column then for 15 days record Where clause as follows

WHERE DT.DATE_ID BETWEEN GETDATE() AND DATEADD(D,15,GETDATE())


SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2010-07-21 : 01:39:17
Dear Sir,

My D_Date table structure is like,

Date_ID Full_Date Days DayName WeekOfTheMonth WeekOfTheYear Month_Num Month_Long Year Quarter
1 01-Jan-08 1 TUESDAY 1 1 1 January 2008 1
2 02-Jan-08 2 WEDNESDAY 1 1 1 January 2008 1
3 03-Jan-08 3 THURSDAY 1 1 1 January 2008 1
4 04-Jan-08 4 FRIDAY 1 1 1 January 2008 1
5 05-Jan-08 5 SATURDAY 1 1 1 January 2008 1

And Date_ID is common both table, So plz tell me wat condition will come in where clause for last 15 days record and last 5 years record in separate separate queary.

Thanks

quote:
Originally posted by sql-programmers

I assume DT.Date_ID column is date column then for 15 days record Where clause as follows

WHERE DT.DATE_ID BETWEEN GETDATE() AND DATEADD(D,15,GETDATE())


SQL Server Programmers and Consultants
http://www.sql-programmers.com/

Go to Top of Page

sql-programmers
Posting Yak Master

190 Posts

Posted - 2010-07-27 : 06:40:32
Sorry for the late reply,

There a date column in your table "Full_Date", But you need to change the format and add in the condition like,

WHERE CONVERT(DATETIME,DT.Full_Date) BETWEEN GETDATE() AND DATEADD(D,15,GETDATE())


SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-07-27 : 07:06:47
For 5 years

between dateadd(dd,datediff(dd,0,getdate()),0) and dateadd(yy,-5,dateadd(dd,datediff(dd,0,getdate()),0))


For 15 days

between dateadd(dd,datediff(dd,0,getdate()),0) and dateadd(dd,-15,dateadd(dd,datediff(dd,0,getdate()),0))



Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page
   

- Advertisement -