May 25, 2005 at 6:55 am
I want to return the Region Name for a organization. The Org_Name of the Organization will be passed into the SP. I know this can be done with a Self Join, but I am having a little difficulting writing the SQL for it.
(Region A is the Region for Organization 1 & 2)
Org_Key Org_Name Region_Key
1 Region A 1
2 Organization 1 1
3 Organization 2 1
Thanks
fryere
May 25, 2005 at 7:02 am
You'd need a self join in this situation but wouldn't it be better to have the region in a separate lookup table? Would be uch simpler to access the data that way.
May 25, 2005 at 7:13 am
It would be easier for a region table in this example, but all organizations will need to be in the same table for other reasons.
Thanks
fryere
May 25, 2005 at 7:19 am
Select Y1.Org_Name, Y2.Org_Name from dbo.YourTable Y1 inner join dbo.YourTable Y2 on Y1.Region_Key = Y2.Org_Key
May 25, 2005 at 12:21 pm
Not that it matters a lot but it will be friendlier if
Select Y1.Org_Name, Y2.Org_Name as Region_Name from dbo.YourTable Y1 inner join dbo.YourTable Y2 on Y1.Region_Key = Y2.Org_Key
* Noel
May 25, 2005 at 12:34 pm
I guessed that he would consider doing this himself. Cause if he didn't I wouldn't want be working with him anyways . (not that it matters either).
May 25, 2005 at 1:50 pm
Thanks for the responses. I will put it use asap.
fryere
May 25, 2005 at 2:08 pm
HTH.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply