stored procedure for dividing a single table into a multiple table.

  • I want to split a table into multiple table.

    what I need is a stored procedure that print a code that goes like this

    /*

    SELECT TOP 50000 * INTO dbo.LR_TABLE_TEST_1 FROM LR_TABLE_TEST ORDER BY NEWID()

    SELECT TOP 50000 * INTO dbo.LR_TABLE_TEST_2 FROM LR_TABLE_TEST WHERE guidsource NOT IN (

    SELECT guidsource FROM LR_TABLE_TEST_1

    ) ORDER BY NEWID()

    SELECT TOP 50000 * INTO dbo.LR_TABLE_TEST_3 FROM LR_TABLE_TEST WHERE guidsource NOT IN (

    SELECT guidsource FROM LR_TABLE_TEST_1 UNION ALL

    SELECT guidsource FROM LR_TABLE_TEST_2

    ) ORDER BY NEWID()

    SELECT * INTO dbo.LR_TABLE_TEST_4 FROM LR_TABLE_TEST WHERE guidsource NOT IN (

    SELECT guidsource FROM LR_TABLE_TEST_1 UNION ALL

    SELECT guidsource FROM LR_TABLE_TEST_2 UNION ALL

    SELECT guidsource FROM LR_TABLE_TEST_3

    ) ORDER BY NEWID()

    */

    I have managed to make the first and second statement (SELECT TOP 50000 * INTO dbo.LR_TABLE_TEST_1 FROM LR_TABLE_TEST ORDER BY NEWID()

    SELECT TOP 50000 * INTO dbo.LR_TABLE_TEST_2 FROM LR_TABLE_TEST WHERE guidsource NOT IN (

    SELECT guidsource FROM LR_TABLE_TEST_1

    ) ORDER BY NEWID() )

    what i need is how to insert a record into the third and succeding table which records are not in the previous table as shown above. and to select * records(not top 50000*) into the final table I am stock on this I need a help . thank you somuch

  • Duplicate Post!

    http://www.sqlservercentral.com/Forums/Topic1307219-391-1.aspx

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Im sorry . cause I think my first post does not explain very well of my problem. 🙁 I edited it and explain it much better now, I want a tored procedue that prints the above codes.. apologies , and thank you 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply