Extract the Lookup Table data from the PricingTable and present in Crystal for viewing and printing
The rows and columns of lookup tables are stored in xml format in the Pricing Table. We use an SQL query for the extraction which brings the data into Crystal with each column listed separately for each row and row value. We then insert the Crystal Cross-Tab report to pivot the table on the column representing the row labels. To include the Table's Notes, we an SQL sub-report into the report header.
The SQL code is extracted from Brandon's WIKI posting, lookup_table_sql He notes in that posting that if not constructed properly, SQL code can damage the database. For the Crystal portion the code is Read Only.
DECLARE @PricingTable INT = (SELECT id FROM PricingTable WHERE PricingTableName = 'PaintProcesses') IF OBJECT_ID('tempdb.dbo.#temp', 'U') IS NOT NULL DROP TABLE #temp; IF OBJECT_ID('tempdb.dbo.#columns', 'U') IS NOT NULL DROP TABLE #columns; DECLARE @XMLData XML = (SELECT TableElementStr FROM PricingTable WHERE ID = @PricingTable ) DECLARE @RowVariable VARCHAR(50) = (SELECT v.VariableName FROM PricingTable pt JOIN variable v ON v.id = pt.RowParam1ID WHERE pt.id = @PricingTable) DECLARE @ColVariable VARCHAR(50) = (SELECT v.VariableName FROM PricingTable pt JOIN variable v ON v.id = pt.ColParamID WHERE pt.id = @PricingTable) SELECT * INTO #Temp FROM ( SELECT Row1ParamValue = Node.Data.value('(Row1ParamValue)[1]', 'varchar(200)') , ColParamValue = ISNULL(Node.Data.value('(ColParamValue)[1]', 'VARCHAR(200)'),'Value') , ElementValue = ISNULL(CAST(Node.Data.value('(ElementValue)[1]', 'VARCHAR(100)') AS DECIMAL(10,4)),0) FROM @XMLData.nodes('/TableElements/TableElement') Node(DATA) ) T SELECT DISTINCT ColParamValue INTO #Columns FROM #Temp ORDER BY ColParamValue DESC; SELECT* FROM #temp ORDER BY ColParamValue
DECLARE @TableName VARCHAR(100) SET @TableName = '{?TableName}'; --Set @TableName = 'PaintProcesses'; SELECT PT.ID, PT.PricingTableName, PT.Notes FROM PricingTable PT WITH(nolock) WHERE PricingTableName = @TableName
Contributor: Steve Gillispie
Date: 12/23/2018
Version: Control 6.10.1811.1501