Skip to content

Instantly share code, notes, and snippets.

@MarshalOfficial
Created October 21, 2015 12:31
Show Gist options
  • Save MarshalOfficial/0fe8342ea589f7f08927 to your computer and use it in GitHub Desktop.
Save MarshalOfficial/0fe8342ea589f7f08927 to your computer and use it in GitHub Desktop.
this script generate random data as output (random varchar,random datetime,random numeric)
SET NOCOUNT ON
GO
CREATE TABLE #RandomData (
RowId INT IDENTITY(1,1) NOT NULL,
SomeVarchar VARCHAR(10),
SomeDateTime DATETIME,
SomeNumeric NUMERIC(16,2) )
GO
DECLARE @count INT
SET @count = 1
WHILE @count <= 50
BEGIN
INSERT INTO #RandomData (SomeVarchar,SomeDateTime,SomeNumeric)
SELECT
CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) + CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) +
CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) + CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) +
CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) + CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) +
CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) + CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) +
CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) + CHAR((ABS(CHECKSUM(NEWID())) % 26) + 97) [SomeVarchar],
DATEADD(MILLISECOND, (ABS(CHECKSUM(NEWID())) % 6000) * -1,
DATEADD(MINUTE, (ABS(CHECKSUM(NEWID())) % 1000000) * -1, GETDATE())) [SomeDateTime],
(ABS(CHECKSUM(NEWID())) % 100001) + ((ABS(CHECKSUM(NEWID())) % 100001) * 0.00001) [SomeNumeric]
SET @count += 1
END
SELECT * FROM #RandomData
DROP TABLE #RandomData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment