Home Forums SQL Server 7,2000 T-SQL EXEC() result as an attribute from another SELECT statement RE: EXEC() result as an attribute from another SELECT statement

  • First, you can make life easier for yourself by using aliases.

    It is already bad enough that all your column names are in ALL CAPS (shouting ?)*** you can at least improve legibility by taking the l-o-o-o-o-n-g table name out of the equation.

    SELECT OSUSR_CYW_TED_EVENTS.[ABSENCETYPEID],

    OSUSR_CYW_TED_EVENTS.[AMOUNT],

    OSUSR_CYW_TED_EVENTS.[AMOUNTEXPENSE],

    [snip]

    FROM [OSAmber].dbo.[OSUSR_CYW_TED_EVENTS]

    Which then becomes

    SELECT

    e.[ABSENCETYPEID],

    e.[AMOUNT],

    e.[AMOUNTEXPENSE],

    [snip]

    FROM [OSAmber].dbo.[OSUSR_CYW_TED_EVENTS] e

    Isn't this less attention-straining now ?

    This goes double if you are selecting columns from different tables in the same select statement. You only need to look at one letter to know where each column is coming from.

    SELECT

    e.[ABSENCETYPEID],

    e.[AMOUNT],

    e.[AMOUNTEXPENSE],

    p.[LONGEMPLOYEENAME]

    [snip]

    FROM [OSAmber].dbo.[OSUSR_CYW_TED_EVENTS] e

    INNER JOIN [OSAmber].dbo.[OSUSR_CYW_EMPLOYEE_PERSONAL_INFORMATION_TABLE] p

    ON p.[EMPLOYEEPRIMARYKEYCOLUMN] = e.[IDENTIFICATIONOFEMPLOYEEABSENTFROMWORKAGAIN

    *** At least you can still consider yourself lucky you do not have to live with big-name company which uses an opaque table / column naming scheme what replaces meaningful names with codes like "AB47Z" instead of "Amount".

    And in the future, please use the [font="Courier New"]IF Code[/font] button on top of the edit window and select "[font="Courier New"]Specified SQL Code[/font]" - this will go a long way to cleaning up the presentation of T-SQL code you post.