Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
how-to-assign-a-random-value-in-a-select-statement-in-sqlserver
/* Much better: https://stackoverflow.com/questions/50402873/how-to-assign-a-random-value-in-a-select-statement-in-sql SELECT T1.COL1, (SELECT TOP 1 t2.COL2 FROM T2 where t1.col1 is not null ORDER BY NEWID() ) FROM T1 */ WITH RANDOM_COLUMNS AS ( SELECT name as col_name ,NEWID() as uuid FROM sys.columns ), ENUMERATED_COLUMNS AS( SELECT ROW_NUMBER() over (order by uuid) as c_id ,col_name ,col_uuid = uuid FROM RANDOM_COLUMNS ), RANDOM_TABLES AS ( SELECT t_id = ROW_NUMBER() OVER (ORDER BY name) ,name as table_name FROM sys.tables T ) SELECT * FROM RANDOM_TABLES T JOIN ENUMERATED_COLUMNS C ON T.t_id = C.c_id
run
|
edit
|
history
|
help
0
Grouping, aggregate function issue when joining to another table
Audit Example
extract part of a string
Rno 37 boat 2
Task2_Final
New
20181117
self join
ss sqlpractice2014
Q2_5MIN