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

Displaying column based on Random number

$
0
0

Hi,

I have been struggling with this for hours and still can't come up with the solution.  What I am looking is to display a column from the below query which equals to the random number generated from CTE. 

Is this possible ?

WITH CTE1 AS
	(
		SELECT bl_URN, bl_date, ROW_NUMBER() OVER(ORDER BY bl_date DESC) AS rowNO,
			bl_underlying1,
			FlOOR(RAND(CHECKSUM(NEWID())) * (@upperNO-@lowerNO)+@lowerNO) AS myRandom		 
		FROM backtesting_bloomberg
	)

	SELECT date2.bl_date, date2.rowNO, (date2.bl_underlying1 / date1.bl_underlying1 - 1) AS und1,
		date2.myRandom
	FROM CTE1 AS date1 JOIN CTE1 AS date2 ON date1.rowNO = date2.rowNO + 1

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>