Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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.PACKAGEREVENUEFROM SA.A_REVENUECOLLECTED_DEPOSIT RDINNER JOIN D_DATE DT ON RD.DATEID = DT.DATE_IDSo 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 followsWHERE DT.DATE_ID BETWEEN GETDATE() AND DATEADD(D,15,GETDATE())SQL Server Programmers and Consultantshttp://www.sql-programmers.com/
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 Quarter1 01-Jan-08 1 TUESDAY 1 1 1 January 2008 12 02-Jan-08 2 WEDNESDAY 1 1 1 January 2008 13 03-Jan-08 3 THURSDAY 1 1 1 January 2008 14 04-Jan-08 4 FRIDAY 1 1 1 January 2008 15 05-Jan-08 5 SATURDAY 1 1 1 January 2008 1And 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 followsWHERE DT.DATE_ID BETWEEN GETDATE() AND DATEADD(D,15,GETDATE())SQL Server Programmers and Consultantshttp://www.sql-programmers.com/
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 Consultantshttp://www.sql-programmers.com/
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