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

Database

 
GeneralRe: Change the date format as shown below. Pin
potlakayala14-Aug-07 3:14
potlakayala14-Aug-07 3:14 
QuestionHow to put values in rows to columns in sql server 2005 Pin
Bhaskar Ravindranath14-Aug-07 0:05
Bhaskar Ravindranath14-Aug-07 0:05 
QuestionSummation in SQL Query Pin
ChandraRam13-Aug-07 23:49
ChandraRam13-Aug-07 23:49 
AnswerRe: Summation in SQL Query Pin
andyharman14-Aug-07 0:57
professionalandyharman14-Aug-07 0:57 
GeneralRe: Summation in SQL Query Pin
ChandraRam14-Aug-07 1:27
ChandraRam14-Aug-07 1:27 
GeneralRe: Summation in SQL Query Pin
andyharman14-Aug-07 1:35
professionalandyharman14-Aug-07 1:35 
GeneralRe: Summation in SQL Query Pin
ChandraRam14-Aug-07 1:53
ChandraRam14-Aug-07 1:53 
GeneralRe: Summation in SQL Query Pin
andyharman14-Aug-07 2:57
professionalandyharman14-Aug-07 2:57 
Hi Chandra

Thats a bit clearer - looks like some-sort of stock allocation problem. The simplest query would be:
select * from MyTable
  where Field1 in (
     select a.Field1
     from MyTable a
     inner join MyTable b
       on b.Field1 <= a.Field1
     group by a.Field1
     having sum(Field2) < 5000)
  order by Field1
The key is the link between a.Field1 and b.Field1. However, this checks rows sequentially. If you have a record with Field1=100 and Field2=1 then earlier rows take precedence.

If you want a more optimised allocation query then you would need to resort to a UDF.

Regards
Andy

If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".

GeneralRe: Summation in SQL Query Pin
ChandraRam14-Aug-07 3:34
ChandraRam14-Aug-07 3:34 
GeneralRe: Summation in SQL Query Pin
andyharman14-Aug-07 5:34
professionalandyharman14-Aug-07 5:34 
GeneralRe: Summation in SQL Query Pin
ChandraRam14-Aug-07 7:13
ChandraRam14-Aug-07 7:13 
GeneralRe: Summation in SQL Query Pin
Blue_Boy14-Aug-07 3:03
Blue_Boy14-Aug-07 3:03 
GeneralRe: Summation in SQL Query Pin
ChandraRam14-Aug-07 3:36
ChandraRam14-Aug-07 3:36 
GeneralRe: Summation in SQL Query Pin
Blue_Boy14-Aug-07 4:52
Blue_Boy14-Aug-07 4:52 
GeneralRe: Summation in SQL Query Pin
ChandraRam14-Aug-07 5:18
ChandraRam14-Aug-07 5:18 
GeneralRe: Summation in SQL Query Pin
Blue_Boy15-Aug-07 0:19
Blue_Boy15-Aug-07 0:19 
GeneralRe: Summation in SQL Query Pin
ChandraRam15-Aug-07 1:20
ChandraRam15-Aug-07 1:20 
GeneralRe: Summation in SQL Query Pin
Blue_Boy15-Aug-07 1:25
Blue_Boy15-Aug-07 1:25 
Questionvariation in the output generated Pin
yuvachandra13-Aug-07 19:55
yuvachandra13-Aug-07 19:55 
AnswerRe: variation in the output generated Pin
Rami Said Abd Alhalim13-Aug-07 20:24
Rami Said Abd Alhalim13-Aug-07 20:24 
QuestionSQL db table limit Pin
firestoper13-Aug-07 19:18
firestoper13-Aug-07 19:18 
AnswerRe: SQL db table limit Pin
blakey40413-Aug-07 21:52
blakey40413-Aug-07 21:52 
AnswerRe: SQL db table limit Pin
Ronni Marker14-Aug-07 0:17
Ronni Marker14-Aug-07 0:17 
AnswerRe: SQL db table limit Pin
okdeshpande14-Aug-07 2:06
okdeshpande14-Aug-07 2:06 
AnswerRe: SQL db table limit Pin
firestoper14-Aug-07 15:09
firestoper14-Aug-07 15:09 

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.