Sunday, November 6, 2011

How to use CAST function in the definition of Linked Tables in NAV

Example 1

The original SQL script for the Linked Table

USE [NavisionTEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[Cronus$UC_CustomTableName]
AS
SELECT DeviceId,
(SELECT DATEADD(hour,
(SELECT DATEDIFF(hour, GETDATE(), getutcdate()) AS EXPR1), CustomTableName.ScanTime) AS EXPR1) AS ScanTime, DisplayLine1
FROM [2ndDATABASE].pfo.dbo.metric_CustomTableName AS CustomTableName
WHERE (DisplayLine1 LIKE '%toner%') OR
(DisplayLine1 LIKE '%cartridge%') ;



Example 2

The same SQL script used to define the Linked Table, being modified with the CAST function

USE [NavisionTEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[Cronus$UC_CustomTableName]
AS
SELECT DeviceId,
(SELECT DATEADD(hour,
(SELECT DATEDIFF(hour, GETDATE(), getutcdate()) AS EXPR1), CustomTableName.ScanTime) AS EXPR1) AS ScanTime,
CAST(DisplayLine1 AS NVARCHAR(250)) AS DisplayLine1
FROM 2ndDATABASE.pfo.dbo.metric_CustomTableName AS CustomTableName
WHERE (DisplayLine1 LIKE '%toner%') OR
(DisplayLine1 LIKE '%cartridge%')

No comments:

Post a Comment

Business Central SaaS Extension Design: Implementing Plant Tracking with AL Event Subscribers

  Extending Business Central SaaS: Plant Tracking Using AL Extensions  1️⃣ Problem Statement In many manufacturing and service-oriented or...