0

I'm trying to insert four random values into my sql table TRandomCodes. I've never tried this but below is the table I'm trying to insert the random values into. The random values I want to insert are at intRandomCodeID 21.

INSERT INTO TRandomCodes ( intRandomCodeID ,intRandomCode ,intStudyID, strTreatment, blnAvailable )
VALUES   ( 1,1000, 12345, 'A', 'T' )
        ,( 2,1001, 12345,   'P', 'T' )
        ,( 3,1002, 12345,   'A', 'T' )
        ,( 4, 1003, 12345,  'P', 'T' )
        ,( 5, 1004, 12345,  'P', 'T' )
        ,( 6, 1005, 12345,  'A', 'T' )
        ,( 7, 1006, 12345,  'A', 'T' )
        ,( 8, 1007, 12345,  'P', 'T' )
        ,( 9, 1008, 12345,  'A', 'T' )
        ,( 10, 1009, 12345, 'P', 'T' )
        ,( 11, 1010, 12345, 'P', 'T' )
        ,( 12, 1011, 12345, 'A', 'T' )
        ,( 13, 1012, 12345, 'P', 'T' )
        ,( 14, 1013, 12345, 'A', 'T' )
        ,( 15, 1014, 12345, 'A', 'T' )
        ,( 16, 1015, 12345, 'A', 'T' )
        ,( 17, 1016, 12345, 'P', 'T' )
        ,( 18, 1017, 12345, 'P', 'T' )
        ,( 19, 1018, 12345, 'A', 'T' )
        ,( 20, 1019, 12345, 'P', 'T' )
        ,( 21, Rand(), Rand(), Rand(), Rand() )
        ,( 22, 5000, 54321, 'A', 'T' )
        ,( 23, 5001, 54321, 'A', 'T' )
        ,( 24, 5002, 54321, 'A', 'T' )
        ,( 25, 5003, 54321, 'A', 'T' )
        ,( 26, 5004, 54321, 'A', 'T' )
        ,( 27, 5005, 54321, 'A', 'T' )
        ,( 28, 5006, 54321, 'A', 'T' )
        ,( 29, 5007, 54321, 'A', 'T' )
        ,( 30, 5008, 54321, 'A', 'T' )
        ,( 31, 5009, 54321, 'A', 'T' )
        ,( 32, 5010, 54321, 'P', 'T' )
        ,( 33, 5011, 54321, 'P', 'T' )
        ,( 34, 5012, 54321, 'P', 'T' )
        ,( 35, 5013, 54321, 'P', 'T' )
        ,( 36, 5014, 54321, 'P', 'T' )
        ,( 37, 5015, 54321, 'P', 'T' )
        ,( 38, 5016, 54321, 'P', 'T' )
        ,( 39, 5017, 54321, 'P', 'T' )
        ,( 40, 5018, 54321, 'P', 'T' )
        ,( 41, 5019, 54321, 'P', 'T' )
  • This link might be helpful: https://stackoverflow.com/questions/1468159/how-can-i-insert-random-values-into-a-sql-server-table – Aura Apr 06 '18 at 15:26
  • Well Rand() will give you a value between 0 and 1. I'm not sure the ranges of your numbers, but basically just multiple Rand() times the max value available. So for intRandomCode you'd put something like "Rand() * 10000". For the letter values you'll have to come up with some type of logic based on the available options. For instance if A and P are the only available options for strTreatment , you could put something like "iif(rand()>= 0.5, 'A', 'P')". – Steve Apr 06 '18 at 15:44

0 Answers0