SQL Server Performance

Naming joined columns??

Discussion in 'General Developer Questions' started by gomikem, Aug 27, 2008.

  1. gomikem New Member

    When I join tables, the columns that they're joined on show up in my queries as Expr1001, Expr1002, and so on. How do I name these? Here is my stored procedure (Thanks for your help!):
    CREATE PROCEDURE usp_rptOpenTicketsByYard

    AS
    SELECT
    dbo.tblTickets.TicketNumber,
    dbo.tblTickets.ProjectTicketOption,
    dbo.tblTickets.[User],
    dbo.tblTickets.ContactInfo,
    dbo.tblTickets.Yard,
    dbo.tblTickets.CallType,
    dbo.tblTickets.CallTypeSub,
    dbo.tblTickets.Summary,
    dbo.tblTickets.AssignedOn,
    dbo.tblTickets.LastUpdatedOn,
    dbo.tblTickets.ClosedOn,
    dbo.tblTickets.TicketCreator,
    dbo.tblTickets.Status,
    dbo.tblTicketStatus.Status,
    dbo.tblTicketPriority.Priority,
    dbo.tblCallTypeSub.[Description],
    dbo.tblTicketCallTypes.CallType,
    dbo.tblUsers.First_Name,
    dbo.tblUsers.Last_Name,
    dbo.tblYardInfo.YardName,
    dbo.tblTickets.CreatedOn,
    dbo.tblTickets.Yard,
    dbo.tblTicketPriority.PriorityStatus,
    CASE
    WHEN dbo.tbltickets.ProjectTicketOption = 0
    THEN "Ticket"
    ELSE "Project"
    END
    AS "Type"

    FROM
    dbo.tblTickets
    RIGHT JOIN dbo.tblTicketStatus ON dbo.tblTicketStatus.StatusID = dbo.tblTickets.Status
    RIGHT JOIN dbo.tblTicketPriority ON dbo.tblTicketPriority.PriorityID = dbo.tblTickets.Priority
    RIGHT JOIN dbo.tblCallTypeSub ON dbo.tblCallTypeSub.CallTypeSubID = dbo.tblTickets.CallTypeSub
    RIGHT JOIN dbo.tblTicketCallTypes ON dbo.tblTicketCallTypes.CallTypeID = dbo.tblTickets.CallType
    RIGHT JOIN dbo.tblUsers ON dbo.tblUsers.UserID = dbo.tblTickets.[User]
    INNER JOIN dbo.tblYardInfo ON dbo.tblYardInfo.YardNumber = dbo.tblTickets.Yard
    WHERE
    ((dbo.tblTicketStatus.Status <> N'closed') AND
    (dbo.tblTickets.Yard = N'1004'))
    GO

  2. FrankKalis Moderator

    Where do there columns show up this way?

  3. gomikem New Member

    They showed up this way in the query results in access. I figured it out though. I just modified my reports to call the new names. Thanks though!
  4. Madhivanan Moderator

    [quote user="gomikem"]
    They showed up this way in the query results in access. I figured it out though. I just modified my reports to call the new names. Thanks though!
    [/quote]
    If you use ACCESS, you should always explicitely alias all the expressions and aggregations (like col1*col2, sum(col1), count(*) etc)

Share This Page