SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with select to convert ref ID to full name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Eagle_f90
Constraint Violating Yak Guru

USA
424 Posts

Posted - 10/16/2012 :  18:40:53  Show Profile  Visit Eagle_f90's Homepage  Reply with Quote
I have a table that referances it's self and was hoping to get help building a SELECT statment that will convert the an ID to full name. The ID is contacned in ParentLocaiton and it referanced LocationID, the full name is contained in LocationName. My table is:

CREATE TABLE dbo.tblLocations
(
    LocationID int IDENTITY(0,1) NOT NULL,
    LocationName varchar(250) NOT NULL,
    SectionID smallint NOT NULL,
    LocationType smallint NOT NULL,
    ParentLocation int NULL,
    MapFileID int NULL,
    CONSTRAINT PK_Locations_LocationID PRIMARY KEY CLUSTERED (LocationID ASC),
    CONSTRAINT FK_Locations_SectionID FOREIGN KEY (SectionID) REFERENCES dbo.tblSectionInfo (SectionID),
    CONSTRAINT FK_Locations_LocationType FOREIGN KEY (LocationType) REFERENCES dbo.tblLocationTypes (LocationTypeID),
    CONSTRAINT FK_Locations_ParentLocation FOREIGN KEY (ParentLocation) REFERENCES dbo.tblLocations (LocationID),
    CONSTRAINT FK_Locations_MapFileID FOREIGN KEY (MapFileID) REFERENCES dbo.tblFiles (FileID)
)


--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

tkizer
Almighty SQL Goddess

USA
37287 Posts

Posted - 10/16/2012 :  19:18:33  Show Profile  Visit tkizer's Homepage  Reply with Quote
Please show us a data example of what you mean. The DDL is very helpful, but we need sample data too.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000