Formatting Query output column width

  • This seems like it should be easy, but I am pretty inexperiecned when it comes to TSQL.

    Every query that I compose, has really wide.  How do I limit the width of these wide columns.

    Example

      select 'ServerRole' = spv.name, 'MemberName' = lgn.name

       from master.dbo.spt_values spv, master.dbo.sysxlogins lgn

       where spv.name = 'sysadmin' and

          spv.low = 0 and

          spv.type = 'SRV' and

          lgn.srvid IS NULL and

          spv.number & lgn.xstatus = spv.number

    gives me

    ServerRole MemberName

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

    sysadmin Domain\SQLadmins

    sysadmin Domain\DBA

    sysadmin admin

    sysadmin sa

  • SELECT CAST(spv.name AS VARCHAR(5)) FROM master.dbo.spt_values spv

    SELECT spv.name FROM master.dbo.spt_values spv

    Derrick Leggett
    Mean Old DBA
    When life gives you a lemon, fire the DBA.

  • or

      select 'ServerRole' = left(spv.name, 10), 'MemberName' = left(lgn.name, 30)

       from master.dbo.spt_values spv, master.dbo.sysxlogins lgn

       where spv.name = 'sysadmin' and

          spv.low = 0 and

          spv.type = 'SRV' and

          lgn.srvid IS NULL and

          spv.number & lgn.xstatus = spv.number

    regards

    Peter

     

  • Better yet hit Ctrl+D and return the results in the data grid




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

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

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