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

if the value of a variable is either 1 or 2, required: to filter a table ordered by date ST that variable cannot have the same value consecutively

$
0
0

ST=such that

The DDL:

DECLARE@tTABLE

(

symbolvarchar(40),

[Date]datetime2,

OTint,

Quantityint,

VPricefloat,

LastPricefloat,

IDNOint,

interIDint

)

INSERTINTO@t VALUES('BIndex','2014-01-17 09:33:03.5317251',1,1,0,2896,4958,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 09:46:01.3519887',2,1,0,2910,4959,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 10:12:01.7911086',1,1,0,2890,4960,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 11:14:01.2087425',2,1,0,2965,4961,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 11:25:18.4861696',1,1,0,3010,4962,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 11:43:01.1887803',2,1,0,3151,4963,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 11:49:02.2058501',1,1,0,3198,4964,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 13:03:03.5256053',2,1,0,3192,4965,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 13:10:01.2759139',1,1,0,3235,4966,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 13:20:04.6329083',2,1,0,3235,4967,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 13:56:01.4371372',1,1,0,3195,4968,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 14:01:02.5625639',1,1,1,3191,4969,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 14:09:01.1756389',2,1,1,3208,4970,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 14:21:44.7000717',1,1,1,3194,4971,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 14:39:02.0604498',2,1,0,3183,4972,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 14:53:11.8068846',1,1,0,3180,4973,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 15:09:02.9112551',2,1,0,3161,4974,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 15:28:02.7837140',2,1,1,3160,4975,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 15:40:07.7412257',1,1,1,3143,4976,60)

INSERTINTO@t VALUES('BIndex','2014-01-17 16:06:52.8480523',1,1,0,3169,4977,60)

select*

from@t

I need to select a table so that only the first (earliest by date) OT row is selected when the previous value for the OT is the same.

ST the OT in date order should always be 1,2,1,2...

The entire table should be:

symbolDate                       OT   Quantity VPrice LastPrice  IDNO  interID

BIndex2014-01-17 09:33:03.53172511     1      0     2896   4958   60

BIndex2014-01-17 09:46:01.35198872     1      0     2910   4959   60

BIndex2014-01-17 10:12:01.79110861     1      0     2890   4960   60

BIndex2014-01-17 11:14:01.20874252     1      0     2965   4961   60

BIndex2014-01-17 11:25:18.48616961     1      0     3010   4962   60

BIndex2014-01-17 11:43:01.18878032     1      0     3151   4963   60

BIndex2014-01-17 11:49:02.20585011     1      0     3198   4964   60

BIndex2014-01-17 13:03:03.52560532     1      0     3192   4965   60

.....


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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