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.
Author |
Topic |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-04-22 : 07:18:45
|
I've following table,PayerTrnxTrnxID | RefNo | RefGroupNo | CtrMonth | CtrYear |PayerNme | DrAmount | PaymentDte | PayerBank---------------------------------------------------------------------------------------------------------1 | 1009 | 1001 | 4 | 2008 | Julie | 54.0000 | 4/19/2008 | KUB2 | 1010 | 1001 | 4 | 2008 | Mick | 30.0000 | 4/19/2008 | KUB3 | 1011 | 1001 | 4 | 2008 | Karl | 21.0000 | 4/19/2008 | KUB 4 | 1012 | 1002 | 5 | 2008 | Bon | 29.0000 | 5/28/2008 | LOP5 | 1013 | 1002 | 5 | 2008 | Julie | 44.0000 | 5/28/2008 | LOP6 | 1014 | 1002 | 5 | 2008 | Marsden | 74.0000 | 5/28/2008 | LOP7 | 1016 | 1002 | 5 | 2008 | Myers | 50.0000 | 5/28/2008 | LOP8 | 1017 | 1003 | 6 | 2008 | Hanna | 30.0000 | 6/29/2008 | HYU9 | 1018 | 1003 | 6 | 2008 | Suzie | 22.0000 | 6/29/2008 | HYUI want to group by RefGroupNo. How to query and get the result as follow,Payment Date | Payer Bank | CtrButionFor |No Of Transaction | Total Amount--------------------------------------------------------------------------------4/19/2009 | KUB | Apr 2008 | 3 | 1055/28/2009 | LOP | May 2008 | 4 | 1976/29/2009 | HYU | Jun 2008 | 2 | 52If possible, Please help ... |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-22 : 07:30:22
|
Try thisselect PaymentDate ,PayerBank ,dateadd(month,ctrmonth-1,dateadd(year,ctryear-1900,0)) as CtrButionFor , count(*) as [No Of Transaction],sum(DrAmount) as [Total Amount] from yourtablegroup by PaymentDate ,PayerBank ,dateadd(month,ctrmonth-1,dateadd(year,ctryear-1900,0)) MadhivananFailing to plan is Planning to fail |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-04-22 : 10:35:58
|
Hi Mr. Madhivanan,After follow your SQL, i got almost what i want. But why CtrButionFor----------------4/1/20095/1/2009How to make it thisCtrButionForApr 2009May 2009??? |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-04-22 : 10:42:50
|
Ok. I know. I can adjust my front-end. It can be display Apr 2009 and soon. TQ |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-22 : 10:42:59
|
quote: Originally posted by Delinda Hi Mr. Madhivanan,After follow your SQL, i got almost what i want. But why CtrButionFor----------------4/1/20095/1/2009How to make it thisCtrButionForApr 2009May 2009???
If you want to show them in formt end application, do formation thereMadhivananFailing to plan is Planning to fail |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-22 : 10:44:09
|
quote: Originally posted by Delinda Ok. I know. I can adjust my front-end. It can be display Apr 2009 and soon. TQ
You understood faster than I typed the same MadhivananFailing to plan is Planning to fail |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-04-22 : 12:54:15
|
Regarding the date as follow,CrtDte--------------4/22/2009 11:33:43 PMi perform,select CONVERT(CHAR(10),CrtDte,121), it will return2009-04-23how to adjust my query above, to make it CrtDte return asCrtDte---------------2009-04-23 00:00:00.000??? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-04-22 : 13:55:40
|
Try something like this:DECLARE @Date DATETIMESET @Date = '4/22/2009 11:33:43 PM'SELECT DATEADD(DAY, DATEDIFF(DAY, 0, @Date), 0)--Result-----------------------2009-04-22 00:00:00.000 |
|
|
dsindo
Starting Member
45 Posts |
Posted - 2009-04-22 : 16:20:05
|
select case when datepart(mm,crtdte) =1 then 'Jan ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =2 then 'Feb ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =3 then 'Mar ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =4 then 'Apr ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =5 then 'May ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =6 then 'Jun ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =7 then 'Jul ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =8 then 'Aug ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =9 then 'Sep ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =10 then 'Oct ' + cast(datepart(yyyy,crtdte) as varchar(12)) when datepart(mm,crtdte) =11 then 'Nov ' + cast(datepart(yyyy,crtdte) as varchar(12)) else 'Dec' end as CtrButionFor |
|
|
|
|
|
|
|