Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Employee Hierarchy Expand / Collapse
Author
Message
Posted Sunday, September 2, 2012 4:56 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 6:51 AM
Points: 201, Visits: 1,144
Can be solved using DECLARE and derived column

DECLARE @OrdNum varchar(5)
DECLARE @Empid int
SET @OrdNum='XZ1'
SET @Empid=200
SELECT * FROM (SELECT OrdNum,Empid,Mgrid,MgrLevel FROM #Orders
WHERE OrdNum=@OrdNum AND Empid=@Empid
) AS A
Post #1353197
Posted Sunday, September 2, 2012 7:38 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 10:28 PM
Points: 35,215, Visits: 31,666
Smash125 (9/2/2012)
Can be solved using DECLARE and derived column

DECLARE @OrdNum varchar(5)
DECLARE @Empid int
SET @OrdNum='XZ1'
SET @Empid=200
SELECT * FROM (SELECT OrdNum,Empid,Mgrid,MgrLevel FROM #Orders
WHERE OrdNum=@OrdNum AND Empid=@Empid
) AS A


Heh... funny enough, that works for the data given. The given data isn't actually hierarchical data (yet).

You don't need the outer SELECT, though.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1353218
Posted Sunday, September 2, 2012 7:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 6:51 AM
Points: 201, Visits: 1,144
Just curious to know that i am not getting it
Post #1353219
Posted Sunday, September 2, 2012 8:13 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 10:28 PM
Points: 35,215, Visits: 31,666
Smash125 (9/2/2012)
Just curious to know that i am not getting it


NP. The following will do the exact same thing as your query. All I did was remove the outer SELECT.

DECLARE @OrdNum varchar(5)
DECLARE @Empid int
SET @OrdNum='XZ1'
SET @Empid=200
SELECT OrdNum,Empid,Mgrid,MgrLevel FROM #Orders
WHERE OrdNum=@OrdNum AND Empid=@Empid



--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1353221
Posted Sunday, September 2, 2012 8:57 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 6:51 AM
Points: 201, Visits: 1,144
.
Post #1353225
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse