Created
April 22, 2012 02:38
-
-
Save battlejj/2442362 to your computer and use it in GitHub Desktop.
Selecting Random IDs for a Subquery in MSSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INSERT INTO | |
| Tickets( | |
| StartedBy, | |
| TicketText | |
| ) | |
| SELECT TOP 1000 | |
| (SELECT TOP 1 id FROM Users WHERE 0.01 >= CAST(CHECKSUM(NEWID(), id) & 0x7fffffff AS float)/CAST (0x7fffffff AS int)) AS StartedBy, | |
| Comments AS TicketText | |
| FROM olddbserver.oldDB.dbo.Tickets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INSERT INTO | |
| Tickets( | |
| StartedBy, | |
| TicketText | |
| ) | |
| SELECT TOP 1000 | |
| ClientId AS StartedBy, | |
| Comments AS TicketText | |
| FROM olddbserver.oldDB.dbo.Tickets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INSERT INTO | |
| Tickets( | |
| StartedBy, | |
| TicketText | |
| ) | |
| SELECT TOP 1000 | |
| (SELECT TOP 1 id FROM Users ORDER BY NEWID()) AS StartedBy, | |
| Comments AS TicketText | |
| FROM olddbserver.oldDB.dbo.Tickets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment