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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-24 : 18:08:32
|
| Phil writes "I want to select all the departments from a table then for each department select all the people that work in the department and return this information. I have set up a select to get the department then i select the employees from where the department = there departmentCREATE PROCEDURE CN_Select_NamesByDepts--used for the banked hours system(@Dept nchar(20)) ASSELECT DISTINCT @Dept = UserList.Department FROM UserList--------------------------------WANT TO RETURN FROM BELOW QUERY!--------------------------------SELECT name ,userid FROM UserListWHERE Department = @Dept i realise theres some code missing what" |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-03-24 : 19:23:19
|
| Confused, I don't think you need an spThis returns your employees groupedselect department, employeefrom employeesorder by department, employeeand this is if you want just one departmentselect department, employeefrom employeeswhere department = 'SQL coders'order by department, employee--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-03-24 : 23:58:09
|
| Why not a sp rrb??? .CREATE PROCEDURE CN_Select_NamesByDepts ( @Dept nchar(20) ) AS set nocount onselect e.* from dept d inner join employee eon e.deptno=d.deptno and d.deptname=@deptGo-------------------------------------------------------------- |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-03-25 : 00:00:29
|
quote: Why not a sp rrb??? .
I have no problem with an sp - but doesn't sound like Phil needs one here - --I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-03-25 : 02:39:08
|
i beg to differ on that , coz phil needs to pass a parameter to select the employees of that department ,a perfect case of using a sp.quote: I have no problem with an sp - but doesn't sound like Phil needs one here
-------------------------------------------------------------- |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-03-25 : 17:10:57
|
quote: i beg to differ on that , coz phil needs to pass a parameter to select the employees of that department ,a perfect case of using a sp.
Ah Nazim, no need to beg - you're more than welcome to differ!Cheers--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
|
|
|