Click here to Skip to main content
15,887,214 members
Home / Discussions / Database
   

Database

 
GeneralRe: Moving Data Between Tables Pin
Meysam Mahfouzi30-Oct-08 8:12
Meysam Mahfouzi30-Oct-08 8:12 
GeneralRe: Moving Data Between Tables Pin
PIEBALDconsult30-Oct-08 10:26
mvePIEBALDconsult30-Oct-08 10:26 
GeneralRe: Moving Data Between Tables Pin
Meysam Mahfouzi31-Oct-08 19:59
Meysam Mahfouzi31-Oct-08 19:59 
Questionproblem to start a sql server service manager Pin
sathyan_829425-Oct-08 2:19
sathyan_829425-Oct-08 2:19 
AnswerRe: problem to start a sql server service manager Pin
Wendelius25-Oct-08 2:24
mentorWendelius25-Oct-08 2:24 
GeneralRe: problem to start a sql server service manager Pin
sathyan_829425-Oct-08 2:51
sathyan_829425-Oct-08 2:51 
GeneralRe: problem to start a sql server service manager Pin
Wendelius25-Oct-08 4:32
mentorWendelius25-Oct-08 4:32 
QuestionEasier way to clip numeric values to min/max boundaries Pin
ScruffR24-Oct-08 15:21
ScruffR24-Oct-08 15:21 
Is there an easy way to restrict values - returned by a SQL select - to certain boundaries?

I've got a some tables like this
dataTBL:
dt                id    x
2008-01-01 10:00  1      5.13
2008-01-01 10:00  2     14.00
2008-01-01 10:00  3     -2.10
2008-01-01 10:00  4      1.65
2008-01-01 11:00  1      5.19
...

compTBL (balancing computation rules):
resultID   baseID   k     d     minX   maxX
100        1        +1.0   0    null   null
100        2        -0.5   0    +3     null
100        3        -0.5  +5    -10     0
200        1        +1.0   0    null   null
200        4        -1.0   10   0      100
...

And I want to calculate for ID 100 e.g. the values
   5.13 * 1.0 + 0.0 (no limits)
+ 14.00 *-0.5 + 0.0 (but at least 3)
+ -2.10 *-0.5 + 5.0 (but at least -10 and maximal 0)

I'm working with Sql Server 2005 and at the moment I'm doing it this way
select 
  dt,
  resultID,
  sum(
    case 
      when isnull(x,0) * k + d < minX then minX
      when isnull(x,0) * k + d > maxX then maxX
      else isnull(x,0) * k + d
    end
  )    
from dataTBL join compTBL on dataID = baseID
group by dt, resultID

This works fine, but I don't like having the same expression three times just for testing <, > and else.
Is there no shorter way to write this case-expression? Or ist there some other function I could use? Is there something like "r = MaximumOf(MinimumOf(x,maxX),minX)" - or even better "r = ClipToBoundaries(x,minX,maxX)"?

Thanks

Andy
AnswerRe: Easier way to clip numeric values to min/max boundaries Pin
Syed Mehroz Alam24-Oct-08 17:48
Syed Mehroz Alam24-Oct-08 17:48 
GeneralRe: Easier way to clip numeric values to min/max boundaries Pin
ScruffR26-Oct-08 22:49
ScruffR26-Oct-08 22:49 
GeneralRe: Easier way to clip numeric values to min/max boundaries Pin
PIEBALDconsult29-Oct-08 5:45
mvePIEBALDconsult29-Oct-08 5:45 
AnswerRe: Easier way to clip numeric values to min/max boundaries Pin
Wendelius24-Oct-08 21:24
mentorWendelius24-Oct-08 21:24 
QuestionProbleum in SQL Query Pin
anoopazgar24-Oct-08 1:01
anoopazgar24-Oct-08 1:01 
AnswerRe: Probleum in SQL Query Pin
Ashfield24-Oct-08 1:36
Ashfield24-Oct-08 1:36 
GeneralRe: Probleum in SQL Query Pin
Paul Conrad24-Oct-08 4:49
professionalPaul Conrad24-Oct-08 4:49 
AnswerRe: Probleum in SQL Query Pin
Jason Lepack (LeppyR64)24-Oct-08 1:46
Jason Lepack (LeppyR64)24-Oct-08 1:46 
AnswerRe: Probleum in SQL Query Pin
Blue_Boy24-Oct-08 8:33
Blue_Boy24-Oct-08 8:33 
Question[Message Deleted] Pin
Member 264536523-Oct-08 22:57
Member 264536523-Oct-08 22:57 
AnswerRe: server broker & sql notification Pin
Ashfield23-Oct-08 23:35
Ashfield23-Oct-08 23:35 
GeneralRe: server broker & sql notification Pin
Member 264536524-Oct-08 0:07
Member 264536524-Oct-08 0:07 
GeneralRe: server broker & sql notification Pin
Ashfield24-Oct-08 1:35
Ashfield24-Oct-08 1:35 
GeneralRe: server broker & sql notification Pin
Member 264536524-Oct-08 3:42
Member 264536524-Oct-08 3:42 
GeneralRe: server broker & sql notification Pin
Ashfield24-Oct-08 4:52
Ashfield24-Oct-08 4:52 
GeneralRe: server broker & sql notification Pin
Member 264536524-Oct-08 5:49
Member 264536524-Oct-08 5:49 
GeneralRe: server broker & sql notification Pin
Ashfield24-Oct-08 6:26
Ashfield24-Oct-08 6:26 

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.