robertsquestion
Technical User
Hi,
I'm using a MS Access 2003 database. One table in there contains almost one million records. Performance is quite bad as there are a lot of complicated queries running on this huge table. I've copied a test-version of this database to SQL-server. Now copying the tables to SQL-server was not a problem, but I'm struggling a bit with translating an important MS Access Query to a SQL-server view.
So let's say the table name is: T_Sales
The table contains the following fields:
Customernr
Orderdate
Amount
Now the goal of the (access) query is to define a period and the year of this period for each record. The period should be defined as follows:
If the Orderdate is before the 30th of June, period should be period one (so 30-04-2009 will be 200901).
If the Orderdate is on or after the 30th of June, period should be period two (so 30-09-2009 will be 200902).
One exception: if the orderdate is between 25th of December and the 31th of December, the period should be the first period of the following year (so 28-12-2009 will be 201001).
With the following (MS Access) SQL this is working fine:
SELECT T_Sales.Customernr, T_Sales.Orderdate, T_Sales.Amount, "30-06-" & Year([Orderdate]) AS calc_date, IIf([Orderdate]<[calc_date],Right([Orderdate],4) & "01",IIf((DateDiff("d",[calc_date],[Orderdate]))>=178,Right([Orderdate],4)+1 & "01",Right([Orderdate],4) & "02")) AS Periode, Left([Periode],4) AS [Year]
FROM T_Sales
ORDER BY T_Sales.Orderdate;
Now my question is: how do I translate this to an SQL server View ? (or: what's the SQL-syntax on SQL server for this one?)
I hope someone can help me out, any help would be appreciated!
Thanks,
Robert
The Netherlands
I'm using a MS Access 2003 database. One table in there contains almost one million records. Performance is quite bad as there are a lot of complicated queries running on this huge table. I've copied a test-version of this database to SQL-server. Now copying the tables to SQL-server was not a problem, but I'm struggling a bit with translating an important MS Access Query to a SQL-server view.
So let's say the table name is: T_Sales
The table contains the following fields:
Customernr
Orderdate
Amount
Now the goal of the (access) query is to define a period and the year of this period for each record. The period should be defined as follows:
If the Orderdate is before the 30th of June, period should be period one (so 30-04-2009 will be 200901).
If the Orderdate is on or after the 30th of June, period should be period two (so 30-09-2009 will be 200902).
One exception: if the orderdate is between 25th of December and the 31th of December, the period should be the first period of the following year (so 28-12-2009 will be 201001).
With the following (MS Access) SQL this is working fine:
SELECT T_Sales.Customernr, T_Sales.Orderdate, T_Sales.Amount, "30-06-" & Year([Orderdate]) AS calc_date, IIf([Orderdate]<[calc_date],Right([Orderdate],4) & "01",IIf((DateDiff("d",[calc_date],[Orderdate]))>=178,Right([Orderdate],4)+1 & "01",Right([Orderdate],4) & "02")) AS Periode, Left([Periode],4) AS [Year]
FROM T_Sales
ORDER BY T_Sales.Orderdate;
Now my question is: how do I translate this to an SQL server View ? (or: what's the SQL-syntax on SQL server for this one?)
I hope someone can help me out, any help would be appreciated!
Thanks,
Robert
The Netherlands