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.
Author |
Topic |
jonhath
Starting Member
13 Posts |
Posted - 2007-08-14 : 14:45:16
|
Hi,I'm running several (40) queries on a single table in order to select demographics. My code works but the only problem is I get 40 different result windows. Here's what it looks like:SELECT TOP (1) submissionkeyFROM dbo.CandidatesWHERE (Sex = 'M') AND (Age >= 18) AND (Age <= 24)ORDER BY NEWID() SELECT TOP (2) submissionkeyFROM dbo.CandidatesWHERE (Sex = 'M') AND (Age >= 25) AND (Age <= 44) ORDER BY NEWID()...etc With these two I get two windows: submissionkey1 1532 147 submissionkey1 145 I'd like to somehow consolidate all the results into one column and export it as a CSV. Each selection needs to be randomized within that selection. I tried some methods that worked if it didn't randomize it (UNION) but I couldn't find a way around it. |
|
ashley.sql
Constraint Violating Yak Guru
299 Posts |
Posted - 2007-08-14 : 14:52:42
|
you can select results to file or you can do bulkinsertAshley Rhodes |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-08-14 : 14:58:16
|
Try inserting into a temp table, then doing one select from that..? |
 |
|
Hommer
Aged Yak Warrior
808 Posts |
Posted - 2007-08-14 : 15:22:20
|
You could also use UNIONs to join all selected result if they are all have the same number of column and same data type. |
 |
|
jonhath
Starting Member
13 Posts |
Posted - 2007-08-14 : 15:35:47
|
UNION doesn't work with ORDER BY NEWID(). I tried inserting it into a temporary table and it works well. |
 |
|
|
|
|