Skip to content
Advertisement

Covert Access Cross tab to sql

I need this converted to a SQL view. This is the code from MS Access:

Any ideas how to re write this into SQL ?

In products I have id, BelsCategoryID. In Categories, I have ID. In Sold, I have BelsProductID and year. – This table shows weather a product is sold in a given year.

I want the result with year as a header and then 0 or 1, if the product has been sold in a given year

Advertisement

Answer

TRANSFORM doesn’t have an exact match in other databases, because it can produce a variable number of columns. For a given set of years, you can use conditional aggregation:

If you want a flexible number of years, you need to use dynamic SQL.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement