Results 1 to 4 of 4

Thread: SQL Server 2005 useful info [includes links to download it]

Threaded View

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Lightbulb SQL Server 2005 useful info [includes links to download it]

    Note that post #4 contains links for downloading SQL Server Express and various other items, and links to more useful information.



    Saw this yesterday - thought it was a really neat T-SQL trick...

    Code:
    update sometable
     set somecol = 'ABC'
     OUTPUT inserted.keycol 'Key', deleted.somecol 'Old', inserted.somecol 'New'
     where keycol = 1
    Will return the 3 columns indicated after the OUTPUT keyword as a SELECT statement after the UPDATE is performed...

    Note that the columns come from those "trigger" like tables - the INSERTED and DELETED tables...

    I get excited easily

    edit: it's only SQL 2005 that will support this

    Here's what it looks like:

    Code:
    begin tran
    select * from lettertyp_t where lettertyp='AP'
    update lettertyp_t set lettertype='ABC' 
       OUTPUT inserted.lettertyp 'Key',deleted.lettertype 'Old'
                       ,inserted.lettertype 'New'
       where lettertyp='AP'
    rollback
    comes back with...

    Code:
    LetterTyp LetterType                     TDate                                                  
    --------- ------------------------------ ------------------------------------------------------ 
    AP        Acknowledgement of Paternity   NULL
    
    (1 row(s) affected)
    
    Key       Old                            New                            
    --------- ------------------------------ ------------------------------ 
    AP        Acknowledgement of Paternity   ABC
    
    (1 row(s) affected)
    Last edited by si_the_geek; Feb 5th, 2008 at 06:14 PM. Reason: added first line

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width