Forum best practice - quoting code

  • Hi,

    I've read Jeff Moden's guide to Forum posting, and have seen examples where code is in its own dedicated window, complete with SS2K5 syntax colouring - so am keen to follow these guidelines.

    However, when I tried to do this, my code appeared as if i'd just typed it in the question text (in one big mess of black text)

    When posting how do I get my code into the dedicated window?

    Thanks,

    Jason

    ---

  • In the reply screen, take a look to the left of the text area. You'll see several IFCode shortcuts. Highlight your code and click the code shortcut, or you can manually wrap it in code tags - [ code ] [ /code ] (remove spaces)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • select'Thanks Gail' union all

    select'Most appreciated' union all

    ------------------------------

    select'Regards.....Jason'

  • While we're on the subject: I've been wanting to experiment with these [ code ] blocks for a while, as they don't always do what I expect.

    SELECT

    'blank line above',

    'and below'

    above omits the blank lines (but seems to add them back between the code block and this text!

    deliberatly using a [ code="noncode" ] codeblock (which isn't allowed, just to try to get the old-style code block)

    EDIT: Changed to [ quote ] as the IE popup error was too annoying.

    SELECT

    'blank line above',

    'and below'

    above gives me some IE errors in preview - but preserves the blank lines

    (syntax highlighter can't find brush for 'noncode')

    [ code="text" ]

    SELECT

    'blank line above',

    'and below'

    above misses out the blank lines again

    Jeff manages to get his code formatted in IE without errors or missing blanks, (or the wierd select problem that means you can't always paste back into SSMS and just run it) How?

  • Tom i don't think noncode is a valid descriptor; i think you need to use plain or text.

    i saved this from a post previously so i had the valid tags handy:

    C++ [ code=”c”] or [ code=”cpp”]

    C# [ code=”c#”] or [ code=”csharp”] or [ code=”c-sharp”]

    CSS [ code=”css”]

    Java [ code=”java”]

    JavaScript [ code=”js”] or [ code=”jscript”] or [ code=”javascript”]

    PHP [ code=”php”]

    Plain (text) [ code=”plain”] or [ code=”text”]

    SQL [ code] or [ code=”sql”]

    VB.NET [ code=”vb”] or [ code=”vbnet”]

    XML [ code=”xml”] or [ code=”xslt”] or [ code=”html”] or [ code=”xhtml”]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Tom Brown (6/23/2009)


    SELECT

    'blank line above',

    'and below'

    above gives me some IE errors in preview - but preserves the blank lines

    (syntax highlighter can't find brush for 'noncode')

    And in Firefox gives those errors twice every time the page is viewed. Would you perhaps consider editing it out for those of us using Firefox?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gail: Done - it was annoying I agree.

  • What I was trying to find out is how Jeff does it

    e.g. this from another thread (which pastes into SSMS well, preserving line breaks and blank lines)

    Jeff Moden (6/20/2009)


    As a side bar, for those interested in a Tally table solution that will work in virtually any release of SQL Server...

    [font="Courier New"]--===== Build the test table as the data source

     CREATE TABLE dbo.TableA (Column1 VARCHAR(5), Column2 VARCHAR(30))

     INSERT INTO dbo.TableA

            (Column1Column2)

     SELECT 'a1''1:3:5:6' UNION ALL

     SELECT 'a2''2:4:5'

    --===== Solution for virtually any version of SQL Server

     INSERT INTO dbo.TableB

            (Column1Column2)

     SELECT a.Column1,

            SUBSTRING(a.Column2t.N+1CHARINDEX(':'a.Column2N+1) - N-1AS Column2

       FROM dbo.Tally t

      CROSS JOIN 

            (SELECT Column1':'+Column2+':' AS Column2 FROM dbo.TableAa

       WHERE LEN(a.Column2)

         AND SUBSTRING(a.Column2N1':'

    [/font]

    But quoting it shows me he's done it the long way with loads of [ color ] and [ font ] tags

    Also wondered if you can still achieve this

    --=============================================================================
    --      Setup
    --=============================================================================
        USE TempDB     --DB that everyone has where we can cause no harm
        SET NOCOUNT ON --Supress the auto-display of rowcounts for appearance/speed
    
    DECLARE @StartTime DATETIME    --Timer to measure total duration
        SET @StartTime = GETDATE() --Start the timer
    
    --=============================================================================
    --      Create and populate a Tally table
    --=============================================================================
    --===== Conditionally drop and create the table/Primary Key
         IF OBJECT_ID('dbo.Tally') IS NOT NULL 
            DROP TABLE dbo.Tally
    
     CREATE TABLE dbo.Tally 
            (N INT, 
             CONSTRAINT PK_Tally_N PRIMARY KEY CLUSTERED (N))
    
    --===== Create and preset a loop counter
    DECLARE @Counter INT
        SET @Counter = 1
    
    --===== Populate the table using the loop and couner
      WHILE @Counter <= 11000
      BEGIN
             INSERT INTO dbo.Tally
                    (N)
             VALUES (@Counter)
    
                SET @Counter = @Counter + 1
        END
    
    

    evidently you can using a

     tag  But Note: that one doesn't paste into SSMS well (all one long line)

Viewing 9 posts - 1 through 8 (of 8 total)

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