Home Forums SQL Server 7,2000 T-SQL What is your favorite "I didn't know that" moment in T-SQL? RE: What is your favorite "I didn't know that" moment in T-SQL?

  • Another one of those A-HA moments, was when I discovered you could select a block of text in SSMS while holding ALT (which is also possible in other Microsoft products).

    Really useful for creating update scripts where the left hand and right hand are the same (for example when I update a dimension/fact table using the staging table):

    UPDATE dest

    SET

    SK_ControlPanel_Status= tmp.SK_ControlPanel_Status

    ,SK_ControlPanel_Nihil= tmp.SK_ControlPanel_Nihil

    ,SK_Date_Expected= tmp.SK_Date_Expected

    ,SK_Date_Received= tmp.SK_Date_Received

    ,SK_Date_LastUpdate= tmp.SK_Date_LastUpdate

    ,Frequency= tmp.Frequency

    ,User_LastUpdate= tmp.User_LastUpdate

    ,UserIDResp= tmp.UserIDResp

    ,Deadline= tmp.Deadline

    ,Date_First_Received= tmp.Date_First_Received

    ,Date_Last_Received= tmp.Date_Last_Received

    ,Date_Last_Validated= tmp.Date_Last_Validated

    ,[Validation_Status]= tmp.[Validation_Status]

    ,[Validation_Rule]= tmp.[Validation_Rule]

    ,[Valid]= tmp.[Valid]

    ,[Job_ID]= tmp.[Job_ID]

    ,[Date_First_Imported]= tmp.[Date_First_Imported]

    ,[Date_Last_Imported]= tmp.[Date_Last_Imported]

    ,[Date_Loaded]= tmp.[Date_Loaded]

    ,[Date_Data_Fixed]= tmp.[Date_Data_Fixed]

    ,[Weeks_Missing]= tmp.[Weeks_Missing]

    ,[Cnt_Initial]= tmp.[Cnt_Initial]

    ,[Cnt_Valid]= tmp.[Cnt_Valid]

    ,[Cnt_Error]= tmp.[Cnt_Error]

    ,[Cnt_Nihil]= tmp.[Cnt_Nihil]

    ,[Cnt_Pending]= tmp.[Cnt_Pending]

    ,[Cnt_Waiting]= tmp.[Cnt_Waiting]

    ,[Cnt_Warning]= tmp.[Cnt_Warning]

    ,[Cnt_Fixed]= tmp.[Cnt_Fixed]

    ,[Cnt_NewVersion]= tmp.[Cnt_NewVersion]

    ,UpdateCtr= dest.UpdateCtr + 1

    ,ModifiedOn= tmp.ModifiedOn

    ,ModifiedBy= tmp.ModifiedBy

    ,RowChangeReason = tmp.RowChangeReason

    FROM

    dbo.FactControlPanel dest

    INNER JOIN

    stagin.FactControlPanel tmp

    ON dest.SK_FactControlPanel = tmp.SK_FactControlPanel

    I just script out the select statement in SSMS, select all the columns while holding alt and paste them into the script. Saves me quite some time.

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