Objects4NAV

Localized SQL views for NAV 2013 R2

Localized SQL views for NAV 2013 R2


MVP_FullColor_ForScreenIn Dynamics NAV 2009 and older we had an option to maintain views in the database. Activating this caused NAV to create a view for each language and every table in the database.

This is a useful thing if you are building BI on top of your SQL and would like to skip all the translation work.

This however had some drawbacks.

  • Every table in the database is maintained
  • Option values are shown as number
  • Boolean is shown as number
  • Global dimension do not have the correct caption
  • Time is shown as DateTime
  • Not easy to see the difference between normal date and closing date

I already discussed this in a post back in 2012. Because of this I never used this built-in option. The solution I created back in 2012 has been upgraded and is now ready and working in NAV 2013 R2.

SQLViewMenu

I start by exporting all tables from the Object Designer as a text file. This text file is imported with the task “Read Option Description”. All options captions from the import are stored in a table in the database.

SQLBIDates

Dates are created according to the Accounting Periods. The BI Dates table keeps multiple fields with information about the date. By joining this table to your SQL query or adding it as a dimension to your OLAP cube you have a lot of options to handle dates and periods.

SQLSelectedTables

The tables required for the views are added to a list. Remember to add he BI Dates table to the list of tables to be used in your business intelligence tool.

SQLCreate

NAV is now ready to create the SQL commands to create the views. The prefix can be used if the views are to be kept in a separate database, which I suggest you do. A prefix can for example be “[Demo Database NAV (7-1)].[dbo].”

SQLExportFile

The file for SQL Management Studio is now ready for execution.

IF  EXISTS(SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'dbo.ENU$Kappi ehf_$Currency'))
DROP VIEW [dbo].[ENU$Kappi ehf_$Currency]
GO
CREATE VIEW [dbo].[ENU$Kappi ehf_$Currency]
AS
SELECT
   [Code] As [Code]
  ,[Last Date Modified] As [Last Date Modified]
  ,[Last Date Adjusted] As [Last Date Adjusted]
  ,[Unrealized Gains Acc_] As [Unrealized Gains Acc_]
  ,[Realized Gains Acc_] As [Realized Gains Acc_]
  ,[Unrealized Losses Acc_] As [Unrealized Losses Acc_]
  ,[Realized Losses Acc_] As [Realized Losses Acc_]
  ,[Invoice Rounding Precision] As [Invoice Rounding Precision]
  ,[Invoice Rounding Type] As [Invoice Rounding Type]
  ,[Amount Rounding Precision] As [Amount Rounding Precision]
  ,[Unit-Amount Rounding Precision] As [Unit-Amount Rounding Precision]
  ,[Description] As [Description]
  ,[Amount Decimal Places] As [Amount Decimal Places]
  ,[Unit-Amount Decimal Places] As [Unit-Amount Decimal Places]
  ,[Realized G_L Gains Account] As [Realized G_L Gains Account]
  ,[Realized G_L Losses Account] As [Realized G_L Losses Account]
  ,[Appln_ Rounding Precision] As [Appln_ Rounding Precision]
  ,CASE [EMU Currency]
    WHEN 1 THEN 'Yes'
    WHEN 0 THEN 'No'
   END As [EMU Currency]
  ,[Currency Factor] As [Currency Factor]
  ,[Residual Gains Account] As [Residual Gains Account]
  ,[Residual Losses Account] As [Residual Losses Account]
  ,[Conv_ LCY Rndg_ Debit Acc_] As [Conv_ LCY Rndg_ Debit Acc_]
  ,[Conv_ LCY Rndg_ Credit Acc_] As [Conv_ LCY Rndg_ Credit Acc_]
  ,[Max_ VAT Difference Allowed] As [Max_ VAT Difference Allowed]
  ,[VAT Rounding Type] As [VAT Rounding Type]
  ,[Payment Tolerance _] As [Payment Tolerance _]
  ,[Max_ Payment Tolerance Amount] As [Max_ Payment Tolerance Amount]
  ,[Wage Amount Rounding Precision] As [Wage Amount Rounding Precision]
  ,[Wage Rate Rounding Precision] As [Wage Rate Rounding Precision]
  ,[Wage Amount Decimal Places] As [Wage Amount Decimal Places]
  ,[Wage Rate Decimal Places] As [Wage Rate Decimal Places]
FROM [Kappi ehf_$Currency]
GO
...
IF  EXISTS(SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'dbo.ENU$Kappi ehf_$BI Dates'))
DROP VIEW [dbo].[ENU$Kappi ehf_$BI Dates]
GO
CREATE VIEW [dbo].[ENU$Kappi ehf_$BI Dates]
AS
SELECT
   [Date] As [Date]
  ,[Date Name] As [Date Name]
  ,[Year] As [Year]
  ,[Week] As [Week]
  ,[Month] As [Month]
  ,[Month Name] As [Month Name]
  ,[Day of Week] As [Day of Week]
  ,[Day Name] As [Day Name]
  ,[Day of Month] As [Day of Month]
  ,CASE [Closing Date]
    WHEN 1 THEN 'Yes'
    WHEN 0 THEN 'No'
   END As [Closing Date]
  ,[SQL Month Name] As [SQL Month Name]
  ,[SQL Day Name] As [SQL Day Name]
  ,[Quarter] As [Quarter]
  ,[Year Month] As [Year Month]
  ,[Year Month Name] As [Year Month Name]
  ,[Month Year  Name] As [Month Year  Name]
  ,[Quarter Name] As [Quarter Name]
  ,[VAT Period] As [VAT Period]
  ,[VAT Period Name] As [VAT Period Name]
  ,[Sorting Date] As [Sorting Date]
  ,[HRMS Integer Start] As [HRMS Integer Start]
  ,[HRMS Integer End] As [HRMS Integer End]
  ,[Day of Year] As [Day of Year]
  ,[Day of Half Year] As [Day of Half Year]
  ,[Day of Quarter] As [Day of Quarter]
  ,[Day of Accounting] As [Day of Accounting]
  ,[Half Years] As [Half Years]
  ,[Half Year of Year] As [Half Year of Year]
  ,CASE [Is Holiday]
    WHEN 1 THEN 'Yes'
    WHEN 0 THEN 'No'
   END As [Is Holiday]
  ,CASE [Is Working Day]
    WHEN 1 THEN 'Yes'
    WHEN 0 THEN 'No'
   END As [Is Working Day]
  ,[Month of Half Year] As [Month of Half Year]
  ,[Month of Quarter] As [Month of Quarter]
  ,[Month of Year] As [Month of Year]
  ,[Quarters of Half Year] As [Quarters of Half Year]
  ,[Quarters of Year] As [Quarters of Year]
  ,[Week of Year] As [Week of Year]
  ,CASE [Is Week Day]
    WHEN 1 THEN 'Yes'
    WHEN 0 THEN 'No'
   END As [Is Week Day]
  ,[Half Year Name] As [Half Year Name]
  ,[Week Name] As [Week Name]
  ,[Fiscal Day] As [Fiscal Date]
  ,[Fiscal Year] As [Fiscal Year]
  ,[Fiscal Week] As [Fiscal Week]
  ,[Fiscal Month] As [Fiscal Month]
  ,[Fiscal Day of Week] As [Fiscal Day of Week]
  ,[Fiscal Day of Month] As [Fiscal Day of Month]
  ,[Fiscal Quarter] As [Fiscal Quarter]
  ,[Fiscal Day of Year] As [Fiscal Day of Year]
  ,[Fiscal Day of Half Year] As [Fiscal Day of Half Year]
  ,[Fiscal Day of Quarter] As [Fiscal Day of Quarter]
  ,[Fiscal Half Years] As [Fiscal Half Years]
  ,[Fiscal Half Year of Year] As [Fiscal Half Year of Year]
  ,[Fiscal Month of Half Year] As [Fiscal Month of Half Year]
  ,[Fiscal Month of Quarter] As [Fiscal Month of Quarter]
  ,[Fiscal Month of Year] As [Fiscal Month of Year]
  ,[Fiscal Quarters of Half Year] As [Fiscal Quarters of Half Year]
  ,[Fiscal Quarters of Year] As [Fiscal Quarters of Year]
  ,[Fiscal Week of Half Year] As [Fiscal Week of Half Year]
  ,[Fiscal Week of Month] As [Fiscal Week of Month]
  ,[Fiscal Week of Quarter] As [Fiscal Week of Quarter]
  ,[Fiscal Week of Year] As [Fiscal Week of Year]
  ,[Fiscal Quarter Name] As [Fiscal Quarter Name]
  ,[Fiscal Half Year Name] As [Fiscal Half Year Name]
  ,[Fiscal Week Name] As [Fiscal Week Name]
  ,[Fiscal Month Name] As [Fiscal Month Name]
FROM [Kappi ehf_$BI Dates]
GO

We now have a localized version of our table data and all the above drawbacks have been fixed. Now go ahead and build your reports or your OLAP cube on top of these views. You can use the BI Dates table for your filter area in the reports to make sure that only available periods are selected.

Leave a Reply