|
/* create temp table */
CREATE TABLE #temp_tb
(
idno INT NOT NULL PRIMARY KEY,
curr_dt DateTime NULL
);
GO
/*
"SELECT Rand()" Will return result like: 0.746842095495527.
In order to recive random number in the range between 1 and 1000 we can use
formula:
ROUND(((1000 - 1 + 1) * Rand()+1),0)
*/
INSERT INTO #temp_tb (idno, curr_dt)
SELECT
ROUND(((1000 - 1 + 1) *
Rand()+1),0),
getdate()
  UNION ALL
SELECT
ROUND(((1000 - 1 + 1) *
Rand()+1),0),
getdate()
  UNION ALL
SELECT
ROUND(((1000 - 1 + 1) *
Rand()+1),0),
getdate();
GO
/* now select data from temp table */
SELECT *
FROM #temp_tb
ORDER BY idno;
GO
DROP TABLE #temp_tb;
|