1

I'm wanting to insert random data from one field into another. I'm unsure of the syntax for this completely, So I'm thinking

icdtbl.icd_id = primary key icdjxn.icd_id = foreign key

 insert into icdjxn (icd_id,patiendID) select top 5000 icd_id from icdtbl order by newid(),select top 5000 patientID from patientTbl order by newid() 

edited for the entirety of what i was looking for.

3
  • 1
    There is no way in SQL (aside from maybe using a cursor?) to select random data. All queries execute deterministically given the same dataset Commented May 16, 2012 at 16:53
  • @HLGEM: msg 156, incorrect syntax near the keyword select Commented May 16, 2012 at 16:55
  • if you order by newid() it will give you a random subset of a table. These do not need to be unique and preferably will not be. Commented May 16, 2012 at 16:56

1 Answer 1

2
insert into icdjxn (icd_id) select top 5000 icd_id from icdtbl order by newid() 

You don't use the word values when using a select.

Sign up to request clarification or add additional context in comments.

1 Comment

could you use this same logic insert two random pieces of data at the same time? (the other side of this junction table)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.