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
 display quarter period records

Author  Topic 

pentahari
Starting Member

26 Posts

Posted - 2008-08-29 : 07:22:03
How to display the particular years record by quarter year period?

Thanks Advance,
Pentahari

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-08-29 : 07:35:53
SELECT DATEPART(q,yourDate)
FROM
yourTable
OR

SELECT YEAR(yourDate)*100 + DATEPART(q,yourDate)
FROM
yourTable

Jim

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-29 : 07:37:18
SELECT DATEADD(QUARTER, DATEDIFF(QUARTER, '19000101', SomeDateTimeColumn), '19000101'),
SUM(SomeOtherColumn)
FROM Table1
GROUP BY DATEADD(QUARTER, DATEDIFF(QUARTER, '19000101', SomeDateTimeColumn), '19000101')
ORDER BY DATEADD(QUARTER, DATEDIFF(QUARTER, '19000101', SomeDateTimeColumn), '19000101')



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

pentahari
Starting Member

26 Posts

Posted - 2008-08-29 : 08:00:38
quote:
Originally posted by Peso

SELECT DATEADD(QUARTER, DATEDIFF(QUARTER, '19000101', SomeDateTimeColumn), '19000101'),
SUM(SomeOtherColumn)
FROM Table1
GROUP BY DATEADD(QUARTER, DATEDIFF(QUARTER, '19000101', SomeDateTimeColumn), '19000101')
ORDER BY DATEADD(QUARTER, DATEDIFF(QUARTER, '19000101', SomeDateTimeColumn), '19000101')



E 12°55'05.25"
N 56°04'39.16"



I am very new to sql. Please give the query for my table.
My table contains camount field and cdate field
how to display the camount total by quarter year period.

For ex:
1/2008 2,00,000
4/2008 2,00,000
7/2008 2,00,000
10/2008 2,00,000

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-29 : 08:09:02
[code]SELECT theQuarter + '/' + theYear,
SUM(caAmount) AS caAmount
FROM (
SELECT DATENAME(YEAR, cDate) AS theYear,
STR(3 * DATEPART(QUARTER, cDate) - 2, 1, 0) AS theQuarter,
caAmount
FROM Table1
) AS d
GROUP BY theQuarter,
theYear
ORDER BY theYear,
theQuarter[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-08-29 : 08:09:39
What is the datatype of cdate?

Jim
Go to Top of Page

pentahari
Starting Member

26 Posts

Posted - 2008-08-29 : 09:51:21
quote:
Originally posted by jimf

What is the datatype of cdate?

Jim


cdate data type is datetime
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-29 : 09:53:58
I rest my case.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -