dbo.usp_longprint - P

type: P ( stored procedure ), modify_date: 2021-11-24 13:33:50

RepoObject_guid: 63B8B46B-A08F-EB11-84F1-A81E8446D5B0

Description

Examples

Parameters

  • @Sql (nvarchar(max))

Entity Diagram

entity-dbo.usp_longprint

References

Object Reference Diagram - 1 1

entity_1_1_objectref-dbo.usp_longprint

Object Reference Diagram - Referenced - 30 0

entity_30_0_objectref-dbo.usp_longprint

Object Reference Diagram - Referencing - 0 30

entity_0_30_objectref-dbo.usp_longprint

sql_modules_definition

dbo.usp_longprint - P script
--code idea from analyticscreator.com
CREATE Procedure dbo.usp_longprint @Sql NVarchar(Max)
As
Begin
    Declare
        @len    Int
      , @CRpos  Int
      , @SqlOut NVarchar(4000);

    Set @len = 2000;

    While @Sql Is Not Null
    Begin
        If Len ( @Sql ) <= @len
        Begin
            Print @Sql;

            Break;
        End;
        Else
        Begin
            Set @CRpos = CharIndex ( Char ( 10 ), @Sql, @len );

            If @CRpos - @len < 2000
                Set @SqlOut = Left(@Sql, @CRpos);
            Else
            Begin
                Raiserror ( 'OOPS! The game is over :(', 16, 1 );
            End;

            Print @SqlOut;

            Set @Sql = Right(@Sql, Len ( @Sql ) - @CRpos);
        End;
    End;
End;