Skip to content

Instantly share code, notes, and snippets.

@DoubleBrotherProgrammer
Created November 20, 2009 19:39
Show Gist options
  • Save DoubleBrotherProgrammer/239710 to your computer and use it in GitHub Desktop.
Save DoubleBrotherProgrammer/239710 to your computer and use it in GitHub Desktop.
-- var to hold random value
declare @field_val int
-- create table var to hold value range [ 0, 512, 1024, 1536, 2048 ]
SELECT 0 AS 'num'
INTO #temp
-- insert data into table var
INSERT INTO #temp VALUES ( 512 )
INSERT INTO #temp VALUES ( 1024 )
INSERT INTO #temp VALUES ( 1536 )
INSERT INTO #temp VALUES ( 2048 )
-- assign random value
SELECT TOP 1 @field_val = num FROM #temp ORDER BY NEWID()
-- show value
SELECT @field_val
-- drop it
DROP TABLE #temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment