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 2000 Forums
 SQL Server Development (2000)
 Stored procedure need help

Author  Topic 

Rita Bhatnagar
Posting Yak Master

172 Posts

Posted - 2001-03-12 : 18:07:08
I wrote this in query analyzer.This works fine but i want reverse of this too.Result:
Bed A/Room 1/East Wing/Lancaster Village
and i need this also
LancaterVillage/East Wing/Room 1/Bed A

Declare @LocationFullText varchar(500)
Select
(Case When Location.ParentID = 0 OR Location.ParentID = ' ' AND Location.Type='C' Then
Institution.Name
Else
Location.Name+', '+(Case When Location_1.ParentID = 0 And Location_1.Type = 'C' Then Institution.Name
Else Location_1.Name+', '+
(Case When Location_2.ParentID = 0 And Location_2.Type = 'C' Then Institution.Name
Else Location_2.Name+', '+
(Case When Location_3.ParentID = 0 And Location_3.Type = 'C' Then Institution.Name Else Location_3.Name+', '+
(Case When Location_4.ParentID = 0
And Location_4.Type = 'C' Then Institution.Name Else
Location_4.Name+', '+ (Case When Location_5.ParentID=0 And Location_5.Type = 'C' Then Institution.Name Else
Location_5.Name+', '+
(Case When Location_6.ParentID = 0
And Location_6.Type = 'C' Then Institution.Name
Else Location_6.Name End)End)End)End)End)End) as LocationFullText into #Temp
FROM ((((((Location LEFT JOIN Location AS Location_1 ON Location.ParentID = Location_1.LocationID)
LEFT JOIN Location AS Location_2 ON Location_1.ParentID = Location_2.LocationID)
LEFT JOIN Location AS Location_3 ON Location_2.ParentID = Location_3.LocationID)
LEFT JOIN Location AS Location_4 ON Location_3.ParentID = Location_4.LocationID)
LEFT JOIN Location AS Location_5 ON Location_4.ParentID = Location_5.LocationID)
LEFT JOIN Location AS Location_6 ON Location_5.ParentID = Location_6.LocationID)
INNER JOIN Institution ON Location.CompanyEntityID = Institution.EntityId



   

- Advertisement -