I need to generate random data. I have some that will generate one of the 5 FACILITY_CODEs at random:
Declare @RAND as float
Select @RAND = 5*RAND(CAST( NEWID() AS varbinary ))
;with CTE_FAC(facility_code, CUM_WEIGHT)
select facility_code, CUM_WEIGHT from DBO.dist_facility where cum_weight > @RAND
SELECT TOP 1 facility_code FROM CTE_FAC ORDER BY CUM_WEIGHT ASC
It would be nice to package this into a neat little function so I can do something like this
How to wrap the above logic into a user defined function?