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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Range report

Author  Topic 

leahsmart
Posting Yak Master

133 Posts

Posted - 2003-04-07 : 05:33:13
Where to begin....

I have a sproc that is an out of range report selecting all the scores that are basically out of their range. There are 3 fields that are used to determine whether a score is out of range they are, Worst, Best and ActualScore. I have used the between statement “WHERE ActualScore NOT BETWEEN Worst AND Best” but that does not work as the Worst score can be greater than the Best score. I am stuck, help.

Thanks


samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-04-07 : 06:29:42
Is this you are looking for

create table #test1
(actualscore int, best int, worst int)
go
insert into #test1 select 4, 2, 9 -- best > actual < worst
insert into #test1 select 8, 3, 6 -- best < worst
insert into #test1 select 9, 5, 2 -- best > worst
insert into #test1 select 4, 9, 2 -- best < actual > worst
go
select * from #test1
where actualscore between best and worst or actualscore between worst and best
go
drop table #test1

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page

leahsmart
Posting Yak Master

133 Posts

Posted - 2003-04-07 : 06:37:35
That does not seem to work. As I have results back which are within range. See below (can't get list to display probably)

ActualScore                                           Best                                                  Worst                                                 
----------------------------------------------------- ----------------------------------------------------- -----------------------------------------------------
0.0 100.0 0.0
0.0 100.0 0.0
59.0 100.0 0.0
91.0 100.0 0.0
0.0 0.0 2.0
0.0 0.0 1.0
15.0 20.0 0.0
3.5099999999999998 10.0 0.0
0.0 0.25 0.0
12.5 5.0 15.0
0.0 100.0 0.0
0.0 100.0 0.0
0.0 0.25 0.0
5.0 2.0 10.0
5.0 2.0 10.0
12.25 5.0 15.0
13.0 20.0 0.0
7.0 15.0 0.0
48.0 60.0 0.0
100.0 100.0 0.0

(20 row(s) affected)


Edited by - leahsmart on 04/07/2003 06:56:54
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-04-07 : 06:58:46
I have given the example for actual score falling between the other two values.. I belive changing to NOT BETWEEN will solve your problem.

Can you Post some few sample data & the desired result

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page

leahsmart
Posting Yak Master

133 Posts

Posted - 2003-04-07 : 07:05:22
I have tried using not between but it does not work. Below is some example data.

Example table

|-----------------------|
| Score | Best | Worst |
|-----------------------|
| 3 | 10 | 0 |
| 6 | 10 | 0 |
| 7 | 10 | 0 |
| 11 | 10 | 0 |
| 7 | 10 | 0 |
| 9 | 10 | 0 |
| 4 | 4 | 10 |
| 2 | 4 | 10 |
| 2 | 4 | 10 |
|-----------------------|


Out of range results from sproc

|-----------------------|
| Score | Best | Worst |
|-----------------------|
| 11 | 10 | 0 |
| 2 | 4 | 10 |
| 2 | 4 | 10 |
|-----------------------|




Edited by - leahsmart on 04/07/2003 07:06:14
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-04-07 : 08:30:38
Try This..


select * from (
select 3 as score, 10 as best, 0 as Worst
union all
select 6, 10, 0
union all
select 7, 10, 0
union all
select 11, 10, 0
union all
select 7, 10, 0
union all
select 9, 10, 0
union all
select 4, 4, 10
union all
select 2, 4, 10
union all
select 2, 4, 10
) as A
where score not between worst and best
and score not between best and worst

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page

leahsmart
Posting Yak Master

133 Posts

Posted - 2003-04-07 : 08:56:35
Thanks, that seems to work, dunno how though. Cheers!!

Go to Top of Page
   

- Advertisement -