Click here to Skip to main content
15,913,939 members
Home / Discussions / Database
   

Database

 
GeneralRe: Case statement issue Pin
VK-Cadec31-Oct-06 9:05
VK-Cadec31-Oct-06 9:05 
QuestionSQL Server 2005 dialect Pin
WSonck31-Oct-06 7:40
WSonck31-Oct-06 7:40 
QuestionSQL Server access problem Pin
hasanali0031-Oct-06 3:34
hasanali0031-Oct-06 3:34 
AnswerRe: SQL Server access problem Pin
Aby Thomas Varghese31-Oct-06 6:32
Aby Thomas Varghese31-Oct-06 6:32 
AnswerRe: SQL Server access problem Pin
hasanali001-Nov-06 1:22
hasanali001-Nov-06 1:22 
QuestionNHibernate and Visual Studio 2005 Pin
WSonck31-Oct-06 2:10
WSonck31-Oct-06 2:10 
QuestionServers backup which are connected by VNP Pin
Amy200031-Oct-06 0:36
Amy200031-Oct-06 0:36 
QuestionHow to do a sequential select in a stored procedure? [modified] Pin
Belfast Child30-Oct-06 23:45
Belfast Child30-Oct-06 23:45 
Hi,
I have a stored proc(below) which assigns tasks to an employee depending on which division they are in.

This is working fine, but is only selecting the first name in the database it comes to.

In order for the workload of task assigning to be spread evenly I need to come up with some way as to "sequentially" select and employee??
ie. each time a do a select I want to pick a different employee from the database until I get to the last employee in which I repeat the process.

I thought of doing a random generator function first but this would probably be unfair as some employees MAY get assigned more tasks than others.


Any ideas??


CREATE PROCEDURE sp_GetAssignedDetails<br />
@roleName nVarChar(50), <br />
@division nVarChar(50),<br />
@actorName nVarChar(50) OUTPUT,<br />
@actorLogon nVarChar(5) OUTPUT<br />
AS<br />
<br />
IF @division = 'North'<br />
BEGIN<br />
  --Get ActorName and ActorLogon if division is North<br />
  SELECT @ActorName = dbo.Actor.ActorName<br />
    FROM dbo.Actor INNER JOIN<br />
      dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
    WHERE dbo.ActorRole.RoleName = @roleName<br />
      and dbo.ActorRole.North = '1'<br />
<br />
  SELECT @actorLogon = dbo.Actor.ActorLogon<br />
    FROM dbo.Actor INNER JOIN<br />
      dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
    WHERE dbo.ActorRole.RoleName = @roleName<br />
      and dbo.ActorRole.North = '1'<br />
END<br />
--Get ActorName and ActorLogon if division is South<br />
ELSE IF @division = 'South' <br />
BEGIN<br />
  SELECT @actorName = dbo.Actor.ActorName<br />
    FROM dbo.Actor INNER JOIN<br />
      dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
    WHERE dbo.ActorRole.RoleName = @roleName<br />
      and dbo.ActorRole.South = '1'<br />
<br />
  SELECT @actorLogon = dbo.Actor.ActorLogon<br />
    FROM dbo.Actor INNER JOIN<br />
      dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
    WHERE dbo.ActorRole.RoleName = @roleName<br />
      and dbo.ActorRole.South = '1'<br />
END<br />
--Get ActorName and ActorLogon if division is West<br />
ELSE IF @division = 'West' <br />
BEGIN<br />
  SELECT @actorName = dbo.Actor.ActorName<br />
    FROM dbo.Actor INNER JOIN<br />
      dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
    WHERE dbo.ActorRole.RoleName = @roleName <br />
      and dbo.ActorRole.West = '1'<br />
<br />
  SELECT @actorLogon = dbo.Actor.ActorLogon<br />
    FROM dbo.Actor INNER JOIN<br />
      dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
    WHERE dbo.ActorRole.RoleName = @roleName <br />
      and dbo.ActorRole.West = '1'<br />
END



-- modified at 16:05 Tuesday 31st October, 2006
AnswerRe: How to do a sequential select in a stored procedure? Pin
Belfast Child31-Oct-06 8:10
Belfast Child31-Oct-06 8:10 
AnswerRe: How to do a sequential select in a stored procedure? Pin
Eric Dahlvang31-Oct-06 11:45
Eric Dahlvang31-Oct-06 11:45 
GeneralRe: How to do a sequential select in a stored procedure? Pin
Belfast Child31-Oct-06 22:29
Belfast Child31-Oct-06 22:29 
GeneralRe: How to do a sequential select in a stored procedure? Pin
Eric Dahlvang1-Nov-06 3:00
Eric Dahlvang1-Nov-06 3:00 
AnswerRe: How to do a sequential select in a stored procedure? [modified] Pin
Damodar Periwal1-Nov-06 8:35
Damodar Periwal1-Nov-06 8:35 
QuestionInsert new rows from a dataset to Sql server database Pin
biglewy30-Oct-06 22:25
biglewy30-Oct-06 22:25 
QuestionWrite to text file from a sql server stored-procedure Pin
flippydeflippydebop30-Oct-06 20:48
flippydeflippydebop30-Oct-06 20:48 
AnswerRe: Write to text file from a sql server stored-procedure Pin
flippydeflippydebop30-Oct-06 22:38
flippydeflippydebop30-Oct-06 22:38 
AnswerRe: Write to text file from a sql server stored-procedure [modified] Pin
flippydeflippydebop30-Oct-06 22:40
flippydeflippydebop30-Oct-06 22:40 
Questioninserting values from select query Pin
dj.rock30-Oct-06 19:46
dj.rock30-Oct-06 19:46 
AnswerRe: inserting values from select query Pin
neilsolent31-Oct-06 0:54
neilsolent31-Oct-06 0:54 
QuestionHow to store an 1:N tree (Hierarchy) Pin
peterchen30-Oct-06 14:52
peterchen30-Oct-06 14:52 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Colin Angus Mackay31-Oct-06 4:37
Colin Angus Mackay31-Oct-06 4:37 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Damodar Periwal31-Oct-06 9:46
Damodar Periwal31-Oct-06 9:46 
AnswerRe: How to store an 1:N tree (Hierarchy) Pin
Eric Dahlvang1-Nov-06 11:31
Eric Dahlvang1-Nov-06 11:31 
QuestionMicrosoft Access VBA Question About ListBoxes... Pin
new_phoenix30-Oct-06 14:15
new_phoenix30-Oct-06 14:15 
QuestionSQL Select Puzzle Pin
neilsolent30-Oct-06 9:51
neilsolent30-Oct-06 9:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.