Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Regarding Alias Names for table

Author  Topic 

kumaran4u
Starting Member

2 Posts

Posted - 2010-02-01 : 06:25:49
Hi, i came across an Stored Procedure(SP) in which i found using multiple alias for a single table. Of coz it can be done using one alias name itself. I'm in to the task of modifying that SP. It has lengthy coding so it will take quite some time to remove all the alias name. I need to know if i leave the alias names as it is will there be any issues related to the performance of the query due to multiple alias names?? if it is yes then i need to remove the alias names else i will leave as it is..

Regards..

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 06:38:22
i dont think there will be performance issues due to alias names, but to be honest your scenario is not much clear for me...may be some sample code will help
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-01 : 06:59:44
Be careful.
A table in a query can have only ONE alias name.
If there are more than one alias then the table is joined repeated for some reason.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mymatrix
Starting Member

24 Posts

Posted - 2010-02-01 : 07:21:02
Just to clarify further:
Implemented code may have equi-joins and inner joins to query the same table with multiple aliases.

For example:
This will return total units status wise with date criteria.

select (select sum(b.units) from tab1 as b where b.status = a.status and b.scheduledate>getdate()) as 'TotalUnits', a.Status
from tab1 as a
group by a.Status



thnks
Gaurav

Even my blood group says be -ve to all the negatives.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-02 : 05:15:26
quote:
Originally posted by mymatrix

Just to clarify further:
Implemented code may have equi-joins and inner joins to query the same table with multiple aliases.

For example:
This will return total units status wise with date criteria.

select (select sum(b.units) from tab1 as b where b.status = a.status and b.scheduledate>getdate()) as 'TotalUnits', a.Status
from tab1 as a
group by a.Status



thnks
Gaurav

Even my blood group says be -ve to all the negatives.


why do you need subquery in this case? wont below be enough?


select sum(case when scheduledate>getdate() then units else 0 end) as 'TotalUnits', Status
from tab1
group by Status
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-02 : 05:25:33
Also dont use single quotes around alias column names

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mymatrix
Starting Member

24 Posts

Posted - 2010-02-02 : 05:59:55
I agree that subquery is not required.
I have used subquery just to provide example of using multiple alias names.

Though i should have stated some other better query. thanks anyways.


**************************************

Even my blood group says be -ve to all the negatives.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-02 : 06:12:07
quote:
Originally posted by mymatrix

I agree that subquery is not required.
I have used subquery just to provide example of using multiple alias names.

Though i should have stated some other better query. thanks anyways.


**************************************

Even my blood group says be -ve to all the negatives.


no problem
you're welcome
Go to Top of Page

kumaran4u
Starting Member

2 Posts

Posted - 2010-02-03 : 00:45:08
Guys, I found some inner joins.. but it is for different tables rather
for the same table.. below i have given the code

Select
xxxxxx
from EveReq er join
StatusMaster es on es.StatusID = er.StatusID
left outer join EveMaster em on em.MasterID=er.EventType
left outer join EveMaster em2 on em2.MasterID=er.ActivityType
left outer join EveMaster em3 on em3.MasterID=er.Area
left outer join EveMaster em6 on em6.MasterID=er.PrimaryTechnology
left outer join EveMaster em7 on em7.MasterID=er.AudienceType
left outer join EveMaster em8 on em8.MasterID=er.Architecture
left outer join EveMaster em9 on em9.MasterID=er.VerticalFocus
left outer join EveMaster em10 on em10.MasterID=er.EventStakeHolders
left outer join EveMaster em11 on em11.MasterID=er.PreferredFormofPayment
left outer join EveMaster em12 on em12.MasterID=er.TemplateOptions
left outer join EveMaster em13 on em13.MasterID=er.CopyBlocks
left outer join EveMaster em14 on em14.MasterID=er.CISCOPhotos
left outer join EveMaster em17 on em17.MasterID=er.VenueStatus
left outer join EveMaster em18 on em18.MasterID=er.TechnicalRating
left outer join EveMaster em19 on em19.MasterID=er.Vendor
left outer join EveMaster em22 on em22.MasterID=er.SetupType
left outer join EveMaster em23 on em23.MasterID=er.WhoShouldAttend
left outer join UserMaster um1 on er.SalesRegion = um1.SalesRegionID
and er.FMMgr = um1.EmailAddress
left outer join UserMaster um2 on um1.UserID = um2.AmmID
left outer join OOOMaster om on er.FieldMarketingManager = om.ApproverID and om.OOOflag=1

based on the discussions in this topic i believe this will not have any issues related to performance... pls suggest me..

Regards..
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-03 : 01:43:07
" i believe this will not have any issues related to performance."

Yes, its fine, although some/many would say that the design is faulty and there should be a separate "lookup" table for each type of Object, whereas this seems to be using the same EveMaster table for all of them.

It is also possible that individual tables would be faster (fewer records to look through), but it could be faster (more of EveMaster cached in memory).
Go to Top of Page
   

- Advertisement -