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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Date format

Author  Topic 

pssumesh2003
Starting Member

35 Posts

Posted - 2009-12-18 : 06:49:46
Hi

i have A table Account
like
Id Accno CreatedDate
1 1005 26/10/09 11:32:18
2 1006 27 /11/09 12:11:23
etc
and Tran table
TId AID Amount TDate
101 1 500 26/12/09 9:12:58
102 2 1000 27 /12/09 7:11:23
when i want select TId using query to check each account has a date to remit amount same day each month to 5 days extra.
i use following query


select TId,Amount from Tran T inner join Account A on A.Id =T.TId
where T.TDate between dateadd(m,datediff(month,A.createdDate,getdate()),A.createdDt)
and
dateadd(dd,5,dateadd(m,datediff(month,A.createdDate,getdate()),A.createdDt))

when executing this i cant any row

my desired output is
all rows having remitence between the date of remitence & 5 day fter that

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2009-12-18 : 08:45:33
So do Accounts only have 5 days from the day in Table A, or a Month and 5 Days?

If its 5 days you want -
Between A.CreatedDate AND DateAdd(d,5,A.CreatedDate)

If it's a month and 5 days you want -
Between A.CreatedDate AND DateAdd(d,5,DateAdd(m,1,A.CreatedDate))
Go to Top of Page
   

- Advertisement -