Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Random cross join

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2014-10-22 : 10:19:53
I want to combine 2 unrelated tables so I am doing a cross join. The problem is the combination brings back several millon records. This is for me to do a test on a stored proc. Is the a way to get a random set back for say 40000 records

SELECT     e.LastName, e.Id AS empID, t.Id AS TeamID, t.Name
FROM dbo.tblEmployee AS e CROSS JOIN
dbo.tblTrkTeam AS t


Dave
Helixpoint Web Development
http://www.helixpoint.com

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-22 : 10:54:55
use TOP(nnn) Percent
Go to Top of Page

lazerath
Constraint Violating Yak Guru

343 Posts

Posted - 2014-10-24 : 12:05:43
As far as I know, the engine will still return a relatively consistent resultset with TOP (nnn) PERCENT. Instead, use it in conjunction with ORDER BY NEWID() to guarantee uniqueness.
Go to Top of Page
   

- Advertisement -