Skip to content

lozn00/AzureSQLProcConvertSQL

Repository files navigation

SqlConvert README

Converting stored procedure code into SQL statements with one click solves the problem of remote debugging and inconvenient testing ne-click conversion of Microsoft SQL Server stored procedures into SQ statements, input parameters, easy to perform modification tests, after the test is completed, one-click reverse into stored procedures. It is used to solve the problem that the remote test stored procedure is difficult to debug and the test code must modify the stored procedure

Requirements

If you have any requirements or dependencies, add a section describing those and how to install and configure them.

Extension Settings

Include if your extension adds any VS Code settings through the contributes.configuration extension point.

For example: This extension contributes the following settings:

  • extension.sqltool.convertSql.enable: Enable/disable this extension.
  • extension.sqltool.convertSql: To Convert Or select the right-click menu Stored Procedure To SQL in the Code Editor

How to Use

Open the SQL file or txt file, right-click in the editing view, and select the menu item Alt text or ctrl+shift+p key keyboard stored

Alt text

Alt text Alt text

Alt text Alt text

Known Issues

Need Format Store Procdure

Release Notes

Users appreciate release notes as you update your extension.

Avoid repeated conversions, increase reversals, optimize conditions, support displaying line numbers for returns, handle situations where stored procedure parameters are 0, and fix situations where the case of stored procedure parameters is affected

vsce package GENEREATE PACKAGE

It is recommended to follow the rules, with a maximum of one comment per line - comments or/* comments */, and multiple comments should be on the same line. Strive for one variable on one line, or for all variables on the same line, with parentheses on a separate line

SUPPORT FIX (15,3)

 CREATE proc [dbo].[A]
(
	@xx varchar(20),
	@x decimal(15,3),
	@size int
)

fix one line (arg)

 ALTER  PROCEDURE [dbo].[XX]    
( @A int, @sSide varchar(2), @B varchar(20), @C int, @e DECIMAL(36,5), @CODE int , @MSG varchar(800) out)

 AS    
    
  return 0;  


GO
)

suggest type of layout

 CREATE  PROCEDURE [dbo].[XX]    
( 
    @A int, @sSide varchar(2), @B varchar(20), @C int, @e DECIMAL(36,5), @CODE int , @MSG varchar(800) out
)

 AS    
    
  return 0;  


GO
)

This type of layout is most compatible

 CREATE  PROCEDURE [dbo].[XX]    
( 
    @A int, 
    @sSide varchar(2), 
    @B varchar(20),
     @C int,
     @e DECIMAL(36,5),
      @CODE int ,
       @MSG varchar(800) out
)

 AS    
    
  return 0;  


GO
)

or

 CREATE  PROCEDURE [dbo].[XX]    
    @A int, 
    @sSide varchar(2), 
    @B varchar(20),
     @C int,
     @e DECIMAL(36,5),
      @CODE int ,
       @MSG varchar(800) out

 AS    
    
  return 0;  


GO
)

CREATE keyword at new line

param at new line

and AS keyword at new Line

So the most perfect

not recommand

 CREATE  PROCEDURE [dbo].[XX]    
( 
    @A int, @sSide varchar(2), @B varchar(20), @C int, @e DECIMAL(36,5), @CODE int , @MSG varchar(800) out
)

 AS    
    
  return 0;  


GO
)
 ALTER  PROCEDURE [dbo].[XX]    
( @A int, @sSide varchar(2), @B varchar(20), @C int, @e DECIMAL(36,5), @CODE int , @MSG varchar(800) out)

 AS    
    
  return 0;  


GO

convert after

src code

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

    
    
    
    
 ALTER  PROCEDURE [dbo].[XX]    
( @A int, @sSide varchar(2), @B varchar(20), @C int, @e DECIMAL(36,5), @CODE int , @MSG varchar(800) out)


 AS    
    
  return 0;  
    
    
    


GO

after -->

SET ANSI_NULLS ON--CONVERT_SUCCESS,Date:2024-04-09T09:40:14.270Z
GO
SET QUOTED_IDENTIFIER ON
GO

    
    
    
    
--  ALTER  PROCEDURE [dbo].[XX]    
--X (
declare @A int;
declare @sSide varchar(2);
declare @B varchar(20);
declare @C int;
declare @e DECIMAL(36,5);
declare @CODE int ;
declare @MSG varchar(800) --out;
--X )
--X
--X
-- set @A='';--[TEMP]0[ARG]
-- set @sSide='';--[TEMP]1[ARG]
-- set @B='';--[TEMP]2[ARG]
-- set @C='';--[TEMP]3[ARG]
-- set @e='';--[TEMP]4[ARG]
-- set @CODE='0';--[TEMP]5[ARG]
-- set @MSG='';--[TEMP]6[ARG]
--  AS    
    
  select 16 as N'responseLine',7 as N'argCount',@A as N'@A',@sSide as N'@sSide',@B as N'@B',@C as N'@C',@e as N'@e',@CODE as N'@CODE',@MSG as N'@MSG';return;--  return 0;  
    
    
    


GO

not support/recommend format

## nor not recommend
 ALTER  PROCEDURE [dbo].[XX]    
( @A int, @sSide varchar(2), 
@B varchar(20), @C int, @e DECIMAL(36,5), @MSG varchar(800) out)
BEGIN

END

You will receive the following error Alt text Failure!Please Format Stored Procedure,Ensure that the double parentheses for stored procedure parameters are on the same line, or that the double parentheses are on a separate line and cannot be on the same line as the parameters

Because the mechanism for recognizing syntax is relatively simple, it involves linear scanning from top to bottom, which increases the complexity of encoding. I do not intend to be compatible with this writing method.

debug print not support

Because annotations are between insert and select, handling this situation can be quite cumbersome

        insert into dbo.sysmergearticles (name, type, objid, sync_objid, artid)
            -- use top 1, distinct could return more than one matching row if status different on partitioned articles
    select top 1 @article, type, objid, @sync_objid
            from dbo.sysmergearticles where artid = @artid


The following code defines multiple comments on a single parameter line, which is not supported
Multiple line parameters, some have 2 parameters per line and some only have one. Currently, only one parameter per line is supported, or all parameters are on the same line


ALTER procedure [sys].[sp_addmergearticle] @publication sysname, /* publication name / @article sysname, / article name / @source_object sysname, / source object name */

@type                   sysname = 'table',                  /* article type

AS

 */



# other function

```select @a,@b,@c,@d,@e```
Select this text and right-click ```@a,@b,@c,@d,@e```
 Select  **Multi Sql param to print str**

Convert the text to the following text

print('@:'+cast(isnull(@,'NULL') as varchar(100))+',''@:'+cast(isnull(@,'NULL') as varchar(100))+',''@:'+cast(isnull(@,'NULL') as varchar(100))+',''@:'+cast(isnull(@,'NULL') as varchar(100))+',''@e:'+cast(isnull(@e,'NULL') as varchar(100)))

## For more information
* [35697438@qq.com](mailto:://356974338@qq.com)
telegram : https://t.me/lozn00
**Enjoy!** 


## Future plans

Support more SQL language