noddy
Computer
- Dec 25, 2002
- 8
I need to create a .csv file grouped by Account, Ccentre with 14 columns, OBAL, JAN, FEB, etc to CBAL.
I have existing views to get the data into the individual parts, the following is for JAN:
SELECT SUBSTRING(GL06001, 1, 4) AS Account, SUBSTRING(GL06001, 5, 4) AS Ccentre, GL06004 AS JAN
FROM dbo.GL060102
WHERE (GL06014 >= CONVERT(DATETIME, '2002-01-01 00:00:00', 102)) AND (GL06014 <= CONVERT(DATETIME, '2002-01-31 00:00:00', 102))
this will give a table of entries for JAN only.
I have tried the following to ADD the views together to give a result with OBAL, JAN as columns but only get OBAL
CREATE VIEW dbo.[24HR_GL06_2002_groupby]
AS
SELECT Account, Ccentre, OBAL
FROM dbo.[24HR_GL06_2002_OB]
union
SELECT Account, Ccentre, JAN
FROM dbo.[24HR_GL06_2002_JAN]
How can I get all 14 periods?
I have existing views to get the data into the individual parts, the following is for JAN:
SELECT SUBSTRING(GL06001, 1, 4) AS Account, SUBSTRING(GL06001, 5, 4) AS Ccentre, GL06004 AS JAN
FROM dbo.GL060102
WHERE (GL06014 >= CONVERT(DATETIME, '2002-01-01 00:00:00', 102)) AND (GL06014 <= CONVERT(DATETIME, '2002-01-31 00:00:00', 102))
this will give a table of entries for JAN only.
I have tried the following to ADD the views together to give a result with OBAL, JAN as columns but only get OBAL
CREATE VIEW dbo.[24HR_GL06_2002_groupby]
AS
SELECT Account, Ccentre, OBAL
FROM dbo.[24HR_GL06_2002_OB]
union
SELECT Account, Ccentre, JAN
FROM dbo.[24HR_GL06_2002_JAN]
How can I get all 14 periods?