I have a query inside of a stored procedure that will retrieve the information that I need, but it is in 3 separate columns. What I ultimately need is one column of distinct codes. Can someone point me in the best direction to do this?
Here's the query:
This will return a recordset similar to:
districtcode regioncode1 storecode1
districtcode regioncode1 storecode2
districtcode regioncode1 storecode3
districtcode regioncode2 storecode4
districtcode regioncode2 storecode5
districtcode regioncode3 storecode6
...and so on
each user has a storecode (or district or region dependant on the user). That store may or may not be a parent store of one or more stores. The user always has the highest level of access, so I need that code and every code under it.
Using the example above, I am trying to get:
districtcode
regioncode1
regioncode2
regioncode3
storecode1
storecode2
storecode3
storecode4
storecode5
storecode6
I'm sure this is probably something very simple... I just need a push. Any help would be much appreciated.
--Mark
Here's the query:
Code:
SELECT ps.StoreCode
,ps2.StoreCode
,ps3.StoreCode
FROM Stores ps (NOLOCK)
LEFT OUTER JOIN Stores ps2 (NOLOCK)
ON ps.StoreID = ps2.ParentStoreID
LEFT OUTER JOIN Stores ps3 (NOLOCK)
ON ps2.StoreID = ps3.ParentStoreID
LEFT OUTER JOIN Users hr (NOLOCK)
ON ps.StoreID=hr.StoreID
WHERE hr.UserName='XYZ'
This will return a recordset similar to:
districtcode regioncode1 storecode1
districtcode regioncode1 storecode2
districtcode regioncode1 storecode3
districtcode regioncode2 storecode4
districtcode regioncode2 storecode5
districtcode regioncode3 storecode6
...and so on
each user has a storecode (or district or region dependant on the user). That store may or may not be a parent store of one or more stores. The user always has the highest level of access, so I need that code and every code under it.
Using the example above, I am trying to get:
districtcode
regioncode1
regioncode2
regioncode3
storecode1
storecode2
storecode3
storecode4
storecode5
storecode6
I'm sure this is probably something very simple... I just need a push. Any help would be much appreciated.
--Mark