From 3c6d4ada15b7649138cc6e16c4eceed47cfd9ff8 Mon Sep 17 00:00:00 2001 From: yarenylmz Date: Wed, 18 Dec 2024 18:47:45 +0300 Subject: [PATCH] Fix print table string limitation (#7) --- .../StoredProcedures/Private_PrintTable.sql | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sql/tSQLt_synapse/StoredProcedures/Private_PrintTable.sql b/sql/tSQLt_synapse/StoredProcedures/Private_PrintTable.sql index 6c89ae8..9e6159f 100644 --- a/sql/tSQLt_synapse/StoredProcedures/Private_PrintTable.sql +++ b/sql/tSQLt_synapse/StoredProcedures/Private_PrintTable.sql @@ -25,7 +25,7 @@ BEGIN @MaxLengthString VARCHAR(100), @ColumnID INT, @MaxColumnID INT, - @Command NVARCHAR(2000); + @Command NVARCHAR(MAX); SELECT @ColumnID = MIN([clm].[column_id]), @@ -93,11 +93,18 @@ BEGIN PRINT REPLICATE('-', LEN(@ColumnList)); IF OBJECT_ID ('tempdb..#PrintTable') IS NOT NULL - TRUNCATE TABLE #PrintTable; + DROP TABLE #PrintTable; + + CREATE TABLE [#PrintTable] + ( + [RowText] [nvarchar](MAX) NOT NULL, + [sequence] [int] NOT NULL + ) + WITH (DISTRIBUTION = ROUND_ROBIN, CLUSTERED INDEX ([sequence])); SET @Command = N' - SELECT RowText, ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS sequence - INTO #PrintTable + INSERT INTO #PrintTable + SELECT RowText, ROW_NUMBER() OVER(ORDER BY RowText) AS sequence FROM ( SELECT CONCAT_WS('', '', ' + @ColumnCastList + ') AS RowText FROM [' + @SchemaName + '].[' + @TableName + '] @@ -111,7 +118,8 @@ BEGIN WHILE @rowCounter <= @totalRows BEGIN SET @rowStr = (SELECT [RowText] FROM #PrintTable WHERE [sequence] = @rowCounter); - PRINT @rowStr + PRINT @rowStr; + SET @rowCounter = @rowCounter + 1; END END END;