OUTPUT & INTO clause in Insert/Update/Delete

6 Posts
2 Users
0 Reactions
59 Views
(@tangomike)
Member
Joined: 1 year ago
Posts: 5
Topic starter   [#155]

If possible, please add options for OUTPUT & INTO when part of an Insert, Update, or Delete. This is in SQL Server.

Also, it would be great to see in a SELECT if 'FOR' got the Before & After options. There is FOR JSON and FOR XML options.

FOR Clause (Transact-SQL) - SQL Server | Microsoft Learn

 

DELETE
FROM
    dbo.p1tProjectNotes
OUTPUT
      DELETED.id        as id
    , DELETED.Notes     as Notes
INTO
    #tMyDeleted
FROM 
    dbo.p1tProjectNotes as pn 
WHERE EXISTS
    (
    SELECT
        1
    FROM
        #tMyInts AS t
    WHERE
        t.id = pn.id
    )
;
        
SELECT
    @JsonOut =
    (
        SELECT
            t.id,
            t.Notes
        FROM
            #tMyDeleted AS t 
        FOR JSON PATH
    )
;
        
IF @JsonOut IS NULL
    BEGIN
        SET @JsonOut = N'[]'
        ;
    END


   
Quote
Guido
(@admin)
Member Admin
Joined: 4 years ago
Posts: 295
 

Hi @tangomike, thanks for your feedback. Are you working with SSSMS Plugin?

Regards

Guido



   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 4 years ago
Posts: 295
 

I'm planning to handle this as follows:

- OUTPUT column list (DELETED.*, INSERTED.*) will use the existing List formatting settings — so your current comma placement, linebreak, and indentation preferences apply automatically.
- INTO (after OUTPUT) will use the same linebreak settings as FROM — since both introduce a table reference, this gives consistent behavior.

Thanks again for the detailed examples, that's really helpful.



   
ReplyQuote
(@tangomike)
Member
Joined: 1 year ago
Posts: 5
Topic starter  

@admin I do use the SSMS plugin. However, I do most of my coding in VS Code. I don't use NPP at all for coding.

I set all the settings in the Desktop App and then have VS Code & SSMS use those settings.



   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 4 years ago
Posts: 295
 

OK, so I will first publish it in the SSMS Plugin. Is it SSMS21/22?



   
ReplyQuote
Guido
(@admin)
Member Admin
Joined: 4 years ago
Posts: 295
 

Hi @tangomike, the new ssms21/22 Release including parsing rules for 

  • output
  • into
  • for xml. for browse, for json

is not available for download.

Will soon also publish the vscode plugin and deskop app

 



   
ReplyQuote
Share: