Code Cut and Paste

  • A deployment was made today with some changes that should allow code cut-and-paste from the forums to SSMS and vice versa.

    It has been tested, but it is a somewhat complicated process. Please report issues and include the browser and SSMS versions.

  • Testing, testing, 1 2 3:

    ;with CTE (Acct) as

    (select '421-15960'

    union all select '421-01824'

    union all select '421-07417'

    union all select '421-11222'

    union all select '421-95138'

    union all select '421-07565'

    union all select '421-15952'

    union all select '421-10398'

    union all select '421-15949'

    union all select '421-01780')

    select *

    from CTE;

    SSMS to SSC: Still having issues with tab justification, IE 7.0.5730.13, SSMS 9.00.4035.00. Not as bad as it used to be. Just the first two indented lines don't line up. The rest look okay.

    SSC to SSMS, I got exactly what shows on the screen, including the uneven justification.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • ;

    with CTE(Acct)

    as (select

    '421-15960'

    union all

    select

    '421-01824'

    union all

    select

    '421-07417'

    union all

    select

    '421-11222'

    union all

    select

    '421-95138'

    union all

    select

    '421-07565'

    union all

    select

    '421-15952'

    union all

    select

    '421-10398'

    union all

    select

    '421-15949'

    union all

    select

    '421-01780')

    select

    *

    from

    CTE ;

    Seems to work okay in FF 3.5 with SMSS 9.00.4035.00. The oddness of the code is exactly what it looks like in SSMS when I used SQLRefactor to format Gus's code sample after pasting it into SSMS.

    Gus, do you still have tabs or do you convert to spaces?

  • Tabs.

    Spaces work just fine. Always have.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Good tests. I think tabs was always the big issue.

  • Okay, yeah tabs are always a problem. I have SSMS use spaces so that's probably why I don't have any issues.

  • I use tabs because that allows me to copy to Word when I'm documenting stuff, and I can adjust layout by adjusting the tabs on the "ruler".

    Advantages/disadvantages to either way of doing it. Minor ones, but they have to be accounted for.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • QA/SSMS/UltraEdit, I have them set to convert tabs to spaces. Thing I found is different people have different tab settings and code can look quite different between the settings. Converting the tabs to spaces makes things consistent between apps and other individuals.

  • I'm a tab-> spaces person myself. Definitely makes it easier dealing with code from other people.

    I'd think the spaces would work in Word with fixed size fonts.

  • I'm a tab-> spaces person myself. Definitely makes it easier dealing with code from other people.

    I'd think the spaces would work in Word with fixed size fonts.

  • Just testing...

    /**********************************************************************************************************************

    Purpose:

    Returns a single result set similar to sp_Space used for all user tables at once.

    Notes:

    1. May be used as a view, stored procedure, or table-valued funtion.

    2. Must comment out 1 "Schema" in the SELECT list below prior to use. See the adjacent comments for more info.

    Revision History:

    Rev 00 - 22 Jan 2007 - Jeff Moden

    - Initital creation for SQL Server 2000

    Rev 01 - 11 Mar 2007 - Jeff Moden

    - Add automatic page size determination for future compliance

    Rev 02 - 05 Jan 2008 - Jeff Moden

    - Change "Owner" to "Schema" in output. Add optional code per Note 2 to find correct schema name

    **********************************************************************************************************************/

    --===== Ensure that all row counts, etc is up do snuff

    -- Obviously, this will not work in a view or UDF and should be removed if in a view or UDF. External code should

    -- execute the command below prior to retrieving from the view or UDF.

    DBCC UPDATEUSAGE(0)

    --===== Return the single result set similar to what sp_SpaceUsed returns for a table, but more

    SELECT DBName = DB_NAME(),

    --SchemaName = SCHEMA_NAME(so.UID), --Comment out if for SQL Server 2000

    SchemaName = USER_NAME(so.UID), --Comment out if for SQL Server 2005

    TableName = so.Name,

    TableID = so.ID,

    MinRowSize = MIN(si.MinLen),

    MaxRowSize = MAX(si.XMaxLen),

    ReservedKB = SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Reserved ELSE 0 END) * pkb.PageKB,

    DataKB = SUM(CASE WHEN si.IndID IN (0,1 ) THEN si.DPages ELSE 0 END) * pkb.PageKB

    + SUM(CASE WHEN si.IndID IN ( 255) THEN ISNULL(si.Used,0) ELSE 0 END) * pkb.PageKB,

    IndexKB = SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Used ELSE 0 END) * pkb.PageKB

    - SUM(CASE WHEN si.IndID IN (0,1 ) THEN si.DPages ELSE 0 END) * pkb.PageKB

    - SUM(CASE WHEN si.IndID IN ( 255) THEN ISNULL(si.Used,0) ELSE 0 END) * pkb.PageKB,

    UnusedKB = SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Reserved ELSE 0 END) * pkb.PageKB

    - SUM(CASE WHEN si.IndID IN (0,1,255) THEN si.Used ELSE 0 END) * pkb.PageKB,

    Rows = SUM(CASE WHEN si.IndID IN (0,1 ) THEN si.Rows ELSE 0 END),

    RowModCtr = MIN(si.RowModCtr),

    HasTextImage = MAX(CASE WHEN si.IndID IN ( 255) THEN 1 ELSE 0 END),

    HasClustered = MAX(CASE WHEN si.IndID IN ( 1 ) THEN 1 ELSE 0 END)

    FROM dbo.SysObjects so,

    dbo.SysIndexes si,

    (--Derived table finds page size in KB according to system type

    SELECT Low/1024 AS PageKB --1024 is a binary Kilo-byte

    FROM Master.dbo.spt_Values

    WHERE Number = 1 --Identifies the primary row for the given type

    AND Type = 'E' --Identifies row for system type

    ) pkb

    WHERE si.ID = so.ID

    AND si.IndID IN (0, --Table w/o Text or Image Data

    1, --Table with clustered index

    255) --Table w/ Text or Image Data

    AND so.XType = 'U' --User Tables

    AND PERMISSIONS(so.ID) 0

    GROUP BY so.Name,

    so.UID,

    so.ID,

    pkb.PageKB

    ORDER BY ReservedKB DESC

    Ok... that's a whole lot better than it's ever been (thanks!) and the copy from the code window was in a WYSIWYG nature. The only remaining problem that I can see is that the intentional blank lines went away. (IE7 and 8) Other than that, compliments to the Developers!

    The other major current problem is that I'm getting the "yellow screen of death" whenever I try to submit a new post. Edit's don't seem to have that problem.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (7/8/2009)

    The other major current problem is that I'm getting the "yellow screen of death" whenever I try to submit a new post. Edit's don't seem to have that problem.

    Jeff,

    This should be fixed now. Could you let us know if you are still encountering any problems along those lines?

    Mel

    Mel HarbourProject ManagerRed Gate Software

Viewing 12 posts - 1 through 11 (of 11 total)

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