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