Skip to content

Commit

Permalink
Fix print table string limitation (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
yarenylmz authored Dec 18, 2024
1 parent 2e20640 commit 3c6d4ad
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions sql/tSQLt_synapse/StoredProcedures/Private_PrintTable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BEGIN
@MaxLengthString VARCHAR(100),
@ColumnID INT,
@MaxColumnID INT,
@Command NVARCHAR(2000);
@Command NVARCHAR(MAX);

SELECT
@ColumnID = MIN([clm].[column_id]),
Expand Down Expand Up @@ -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 + ']
Expand All @@ -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;

0 comments on commit 3c6d4ad

Please sign in to comment.