Click here to Skip to main content
15,885,278 members
Home / Discussions / Database
   

Database

 
Question(Expiring Next Month) Problem Pin
Jassim Rahma11-Aug-14 21:45
Jassim Rahma11-Aug-14 21:45 
AnswerRe: (Expiring Next Month) Problem Pin
Kornfeld Eliyahu Peter11-Aug-14 21:58
professionalKornfeld Eliyahu Peter11-Aug-14 21:58 
GeneralRe: (Expiring Next Month) Problem Pin
Jassim Rahma11-Aug-14 23:40
Jassim Rahma11-Aug-14 23:40 
GeneralRe: (Expiring Next Month) Problem Pin
GuyThiebaut12-Aug-14 1:42
professionalGuyThiebaut12-Aug-14 1:42 
GeneralRe: (Expiring Next Month) Problem Pin
Bernhard Hiller12-Aug-14 21:28
Bernhard Hiller12-Aug-14 21:28 
GeneralRe: (Expiring Next Month) Problem Pin
GuyThiebaut12-Aug-14 21:45
professionalGuyThiebaut12-Aug-14 21:45 
AnswerRe: (Expiring Next Month) Problem Pin
GuyThiebaut11-Aug-14 22:07
professionalGuyThiebaut11-Aug-14 22:07 
QuestionT-Sql Distribute data into groups based on existing numbers Pin
dreaddan10111-Aug-14 10:42
dreaddan10111-Aug-14 10:42 
Hi, i've been looking at moving one of our processed from excel (+vba) into t-sql to make life easier but am stuck.

We have lots of tasks that are assigned to work groups which we want to distribute evenly across the work groups. This is a simple task for ntile.. However when these tasks are no longer required they are removed which leaves the groups uneven. When new tasks are added we want to still try to keep these groups balanced.




EG Existing groups :
GroupName - Task Count
Group1 - 1000
Group2 - 999
Group3 - 998

If we were to add 6 new tasks they would have more assigned to Group 2 & 3 as they have less than group 1.
Task 1 - Group3
Task 2 - Group3
Task 3  -Group2
Task 4 - Group1
Task 5 - Group2
Task 6 - Group3

Sample tables
SQL
Create table GroupTable
(GroupID int, Name varchar(200) )
Insert into GroupTable values (1,'Group1')
Insert into GroupTable values (2,'Group2')
Insert into GroupTable values (3,'Group3')


Create table Jobs(jobid int identity(1,1), name varchar(100),Groupid int)
--Existing tasks
Insert into Jobs(name,Groupid) values ('Task1',1)
Insert into Jobs(name,Groupid) values ('Task2',1)
Insert into Jobs(name,Groupid) values ('Task3',1)
Insert into Jobs(name,Groupid) values ('Task4',1)
Insert into Jobs(name,Groupid) values ('Task5',2)
Insert into Jobs(name,Groupid) values ('Task6',2)
Insert into Jobs(name,Groupid) values ('Task6',2)
Insert into Jobs(name,Groupid) values ('Task7',3)

-- New tasks
Insert into Jobs(name) values ('TaskA')
Insert into Jobs(name) values ('TaskB')
Insert into Jobs(name) values ('TaskC')
Insert into Jobs(name) values ('TaskD')
Insert into Jobs(name) values ('TaskE')
Insert into Jobs(name) values ('TaskF')

This gives us 6 unassigned tasks and a uneven group assignment

SQL
GROUPNAME   TASK_COUNT
<none>      6
Group1      4
Group2      3
Group3      2

This means the new tasks will be assigned like this

TaskA - Group3
TaskB - Group3
TaskC - Group2
TaskD - Group1
TaskE - Group2
TaskF - Group3


Can anyone help?
Thanks
Dan
AnswerRe: T-Sql Distribute data into groups based on existing numbers Pin
Jörgen Andersson13-Aug-14 22:44
professionalJörgen Andersson13-Aug-14 22:44 
QuestionProblem with Decimal Places and Rounding off Pin
Vimalsoft(Pty) Ltd9-Aug-14 23:02
professionalVimalsoft(Pty) Ltd9-Aug-14 23:02 
AnswerRe: Problem with Decimal Places and Rounding off Pin
Kornfeld Eliyahu Peter10-Aug-14 0:00
professionalKornfeld Eliyahu Peter10-Aug-14 0:00 
GeneralRe: Problem with Decimal Places and Rounding off Pin
Vimalsoft(Pty) Ltd10-Aug-14 1:28
professionalVimalsoft(Pty) Ltd10-Aug-14 1:28 
QuestionSelect and Update Pin
jkirkerx8-Aug-14 11:43
professionaljkirkerx8-Aug-14 11:43 
AnswerMy none soup version Pin
jkirkerx8-Aug-14 12:11
professionaljkirkerx8-Aug-14 12:11 
AnswerRe: Select and Update Pin
PIEBALDconsult8-Aug-14 20:57
mvePIEBALDconsult8-Aug-14 20:57 
Answer[Solved] Pin
jkirkerx10-Aug-14 12:50
professionaljkirkerx10-Aug-14 12:50 
AnswerRe: Select and Update Pin
MeutherOlaf11-Aug-14 20:36
MeutherOlaf11-Aug-14 20:36 
QuestionWeird problem with UNION query in Access 2010 Pin
Peter R. Fletcher8-Aug-14 3:46
Peter R. Fletcher8-Aug-14 3:46 
QuestionFind the right SSMS Pin
Corporal Agarn8-Aug-14 1:53
professionalCorporal Agarn8-Aug-14 1:53 
AnswerRe: Find the right SSMS Pin
Richard Deeming8-Aug-14 2:18
mveRichard Deeming8-Aug-14 2:18 
GeneralRe: Find the right SSMS Pin
Corporal Agarn8-Aug-14 2:25
professionalCorporal Agarn8-Aug-14 2:25 
Questionsql server insert into select + in select part if else Pin
Karan_TN7-Aug-14 0:16
Karan_TN7-Aug-14 0:16 
AnswerRe: sql server insert into select + in select part if else Pin
Mycroft Holmes7-Aug-14 0:55
professionalMycroft Holmes7-Aug-14 0:55 
QuestionHow to change multiple date formats in Sql server Pin
AzeeM_R6-Aug-14 2:51
professionalAzeeM_R6-Aug-14 2:51 
AnswerRe: How to change multiple date formats in Sql server Pin
Corporal Agarn6-Aug-14 3:38
professionalCorporal Agarn6-Aug-14 3:38 

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.