Click here to Skip to main content
15,883,705 members
Home / Discussions / Database
   

Database

 
GeneralRe: vb.net with mysql Pin
PIEBALDconsult9-Feb-15 3:47
mvePIEBALDconsult9-Feb-15 3:47 
AnswerRe: vb.net with mysql Pin
ZurdoDev9-Feb-15 4:01
professionalZurdoDev9-Feb-15 4:01 
GeneralRe: vb.net with mysql Pin
Jörgen Andersson9-Feb-15 4:09
professionalJörgen Andersson9-Feb-15 4:09 
QuestionRe: vb.net with mysql Pin
Eddy Vluggen9-Feb-15 5:53
professionalEddy Vluggen9-Feb-15 5:53 
QuestionPopulate one table from another Pin
Corporal Agarn6-Feb-15 4:50
professionalCorporal Agarn6-Feb-15 4:50 
QuestionRe: Populate one table from another Pin
Wendelius6-Feb-15 5:23
mentorWendelius6-Feb-15 5:23 
AnswerRe: Populate one table from another Pin
Corporal Agarn6-Feb-15 6:49
professionalCorporal Agarn6-Feb-15 6:49 
AnswerRe: Populate one table from another Pin
Jörgen Andersson9-Feb-15 21:29
professionalJörgen Andersson9-Feb-15 21:29 
Tough one, it took me a while to understand what you wanted, and I still may have misunderstood the purpose.
Anyway, here's a try, tell me if I'm off the target.

Since there is no UnGroup or UnCount function in SQL we have to create that ourselves.
One way is to use an auxiliary Sequence. Here's a fairly fast way to create a sequence:
SQL
CREATE TABLE numbersequence (Number  int  not null);
INSERT INTO numbersequence(Number)
SELECT  TOP 100 row_number() over(order by t1.number) as N
FROM    master..spt_values t1 
CROSS JOIN master..spt_values t2
;
Adjust for the size you need.
Now we can "Uncount" the table and create a rownumber to join on:
SQL
select  testid
       ,ROW_NUMBER() OVER(order by testid) AS rn
from    MyTestCounts tc,numbersequence n
where   tc.cnt >= n.number
The whole query to connect unrelated IDX to TestID would look like this:
SQL
with counts as (
    select  testid
           ,ROW_NUMBER() OVER(order by testid) AS rn
    from    MyTestCounts tc,numbersequence n
    where   tc.cnt >= n.number
    )
,tqb as (
    SELECT  TOP (select sum(cnt) from MyTestCounts) TQB.IDX
           ,ROW_NUMBER() OVER(order by testid) AS rn
    FROM    MyTestBase TQB
    WHERE   TestID IS NULL
    ORDER BY NEWID()
    )
select  IDX,TestID
from    counts c
join    tqb t
    on  c.rn = t.rn

Here's[^] the fiddle.
Wrong is evil and must be defeated. - Jeff Ello

GeneralRe: Populate one table from another Pin
Corporal Agarn10-Feb-15 0:42
professionalCorporal Agarn10-Feb-15 0:42 
GeneralRe: Populate one table from another Pin
Corporal Agarn10-Feb-15 2:23
professionalCorporal Agarn10-Feb-15 2:23 
GeneralRe: Populate one table from another Pin
Jörgen Andersson10-Feb-15 4:23
professionalJörgen Andersson10-Feb-15 4:23 
AnswerRe: Populate one table from another Pin
Rony8910-Feb-15 17:00
Rony8910-Feb-15 17:00 
GeneralRe: Populate one table from another Pin
Corporal Agarn11-Feb-15 0:43
professionalCorporal Agarn11-Feb-15 0:43 
QuestionHow to upgrade a SQL Server Mobile database? [Solved] Pin
TMattC6-Feb-15 3:03
TMattC6-Feb-15 3:03 
AnswerRe: How to upgrade a SQL Server Mobile database? Pin
TMattC6-Feb-15 8:55
TMattC6-Feb-15 8:55 
AnswerRe: How to upgrade a SQL Server Mobile database? [Solved] Pin
TMattC8-Feb-15 20:19
TMattC8-Feb-15 20:19 
QuestionFull Text Search sqlserver Pin
samanehahmadi2-Feb-15 19:26
professionalsamanehahmadi2-Feb-15 19:26 
AnswerRe: Full Text Search sqlserver Pin
Eddy Vluggen2-Feb-15 22:35
professionalEddy Vluggen2-Feb-15 22:35 
QuestionShrink Problem After Compress Pin
en.Mahdi31-Jan-15 2:58
en.Mahdi31-Jan-15 2:58 
QuestionRe: Shrink Problem After Compress Pin
Richard MacCutchan31-Jan-15 6:15
mveRichard MacCutchan31-Jan-15 6:15 
QuestionOracle Connection User Name and Password [UPDATE] Pin
Kevin Marois30-Jan-15 11:24
professionalKevin Marois30-Jan-15 11:24 
Questionhow can i transfer data Pin
Member 1141305829-Jan-15 12:55
Member 1141305829-Jan-15 12:55 
AnswerRe: how can i transfer data Pin
Mycroft Holmes29-Jan-15 13:41
professionalMycroft Holmes29-Jan-15 13:41 
GeneralRe: how can i transfer data Pin
Member 114130581-Feb-15 5:23
Member 114130581-Feb-15 5:23 
AnswerRe: how can i transfer data Pin
Umer Akram29-Jan-15 18:52
Umer Akram29-Jan-15 18:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.