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 2008 Forums
 Transact-SQL (2008)
 Help with select to convert ref ID to full name

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2012-10-16 : 18:40:53
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

38200 Posts

Posted - 2012-10-16 : 19:18:33
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
   

- Advertisement -