Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to use TSQL to complete the below task...

$
0
0

SELECT Initial.PrismID,  PrismReadingHist.V4, PrismReadingHist.V5, PrismReadingHist.V6,  PrismReadingHist.DateTime , PrismReadingHist.cycle FROM  Initial LEFT OUTER JOIN PrismReadingHist ON Initial.PrismID = PrismReadingHist.Prism WHERE  (Initial.active = 'Y') and ((prismreadinghist.date = '2013-08-19' and prismreadinghist.cycle = 46)  or (prismreadinghist.date = '2013-08-19' and prismreadinghist.cycle = 45)  or (prismreadinghist.date = '2013-08-19' and prismreadinghist.cycle = 44)  or (prismreadinghist.date = '2013-08-19' and prismreadinghist.cycle = 43)  or (prismreadinghist.date = '2013-08-19' and prismreadinghist.cycle = 42))  ORDER BY PrismReadingHist.Prism, PrismReadingHist.V4, PrismReadingHist.V5, PrismReadingHist.V6

Some of the result set are listed below re the above SQL

PrismID V4                  V5                  V6          DateTime                 Cycle

D0447E 836771.310102 818451.018116 3.999588 2013-08-19 21:36:00 44
D0447E 836771.310193 818451.019171 3.999748 2013-08-19 21:07:00 43
D0447E 836771.310247 818451.018108 3.999233 2013-08-19 22:07:00 45
D0447E 836771.310326 818451.018428 3.999631 2013-08-19 22:36:00 46
D0447E 836771.310914 818451.017908 3.999654 2013-08-19 20:36:00 42


D0447W 836767.168239 818451.226007 4.031086 2013-08-19 21:36:00 44
D0447W 836767.168462 818451.226277 4.031124 2013-08-19 22:35:00 46
D0447W 836767.168486 818451.226077 4.031055 2013-08-19 22:06:00 45
D0447W 836767.169037 818451.225712 4.031179 2013-08-19 20:35:00 42


D0449E 836771.401689 818453.078862 4.009016 2013-08-19 21:09:00 43
D0449E 836771.401762 818453.077779 4.008992 2013-08-19 21:38:00 44
D0449E 836771.401888 818453.078076 4.009007 2013-08-19 22:38:00 46
D0449E 836771.401911 818453.077832 4.008949 2013-08-19 22:09:00 45
D0449E 836771.402431 818453.077555 4.009019 2013-08-19 20:38:00 42

I have another VB code to produce the Mean/Medan value from the result set

MM = 0
Select Case UBound(NumericArray)
    Case 5: MM = NumericArray(3)
    Case 4: MM = (NumericArray(2) + NumericArray(3)) / 2
    Case 3: MM = NumericArray(2)
    Case 2: MM = (NumericArray(1) + NumericArray(2)) / 2
    Case 1: MM = NumericArray(1)
End Select

where NumericArry is an array contains the 1 to 5 values of the SQL result set of each Prism

e.g

D0449E 836771.401689 818453.078862 4.009016 2013-08-19 21:09:00 43
D0449E 836771.401762 818453.077779 4.008992 2013-08-19 21:38:00 44
D0449E 836771.401888 818453.078076 4.009007 2013-08-19 22:38:00 46
D0449E 836771.401911 818453.077832 4.008949 2013-08-19 22:09:00 45
D0449E 836771.402431 818453.077555 4.009019 2013-08-19 20:38:00 42

D0447W 836767.168239 818451.226007 4.031086 2013-08-19 21:36:00 44
D0447W 836767.168462 818451.226277 4.031124 2013-08-19 22:35:00 46
D0447W 836767.168486 818451.226077 4.031055 2013-08-19 22:06:00 45
D0447W 836767.169037 818451.225712 4.031179 2013-08-19 20:35:00 42

Result would be

Prism     MM_V4               MM_V5               MM_V6     ExecutionTime       CountOftheRecSET 

D0449E 836771.401888 818453.078076 4.009007 2013-08-19 22:59 5

D0447W 836767.168474 818451.226042 4.031105 2013-08-19 22:59 4

Please advise how to have a TSQL to fine tune the SQL to come out the final record for each prism

Many Thanks !!



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>