Copy pasting SQL code changes some symbols

  • When copy-pasting some code from this site to another tool, e.g. SSMS, it's possible some symbols are changed.

    For example:

    comments are transformed into hyphens. -- becomes —

    single quote become a "smart quote": ' becomes ‘

    edit: apparently the symbols are also changed when inputting the text into a post. Probably some HTML issue?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Test posting here frmo SSMS with various code. I'll paste below, highlight, and click "insert/edit code sample"

    ALTER PROCEDURE [dbo].[SendMonthlyNotifications]
    -- this is a comment
    AS
    BEGIN
    DECLARE cur CURSOR LOCAL FAST_FORWARD FOR
    SELECT MNR.email, MNR.name
    FROM dbo.MonthlyNotificationRecipients AS MNR
    ORDER BY MNR.name;

    DECLARE @name NVARCHAR(200) = 'someemail@somedomain.sometld';
    DECLARE @email NVARCHAR(200);

    OPEN cur;

    Now I'll click teh button and paste in there

    ALTER PROCEDURE [dbo].[SendMonthlyNotifications]
    -- this is a comment
    AS
    BEGIN
    DECLARE cur CURSOR LOCAL FAST_FORWARD FOR
    SELECT MNR.email, MNR.name
    FROM dbo.MonthlyNotificationRecipients AS MNR
    ORDER BY MNR.name;

    DECLARE @name NVARCHAR(200) = 'someemail@somedomain.sometld';
    DECLARE @email NVARCHAR(200);

    OPEN cur;
  • I don't see this behavior, Win 10, Chrome. I suspect there are some client side things going on for some users.

  • I think it happens when you're not using the code block, but rather inserting the code directly in the message body.

    Try typing the single line comment: - - (but without the space).

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Koen: some of this might be related to behavior I have documented here:

    MAJOR DATA LOSS ISSUE TO FIX ASAP: code in code block treated as standard HTML

     

    But, to be fair to the SSC.com team: I don't think that one should expect that code existing outside of a code block will remain untouched. This is part of why we have code blocks, not just to apply nice formatting, but also as a way to declare certain elements on the page as "please don't alter / process". So yes, I would fully expect that two hyphens with no space between will be translated into an — or something similar.

    Take care, Solomon..

     

     

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply