Help On Query

  • CREATE TABLE [dbo].[tmp]([msisdn] varchar(20))

    DECLARE @intFlag bigINT

    SET @intFlag = 15210000000

    WHILE (@intFlag <=15219999999)

    BEGIN

    PRINT @intFlag

    insert into tmp select @intFlag

    set @intFlag= @intFlag + 1

    END

    GO

    Is there any short way to perform this

  • this is very urgent somebody help...

  • When something is really urgent it would benefit you to provide more details. Doing this quickly is going to depend on your meaning of quickly. Certainly using a while loop for 10,000,000 inserts is going to be horrendously slow.

    You could use a tally table and it will be a lot faster. This took about 43 seconds on my machine.

    WITH

    E1(N) AS (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))dt(n)),

    E2(N) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows

    E4(N) AS (SELECT 1 FROM E2 a, E2 b), --10E+4 or 10,000 rows max

    E5(N) as (SELECT 1 from E4 a, E4 b),

    cteTally(N) AS

    (

    SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E5

    )

    insert tmp

    select '1521' + right(REPLICATE('0', 6) + CAST(N - 1 as varchar(10)), 7)

    from cteTally

    where N <= 10000000

    You should read up on them here. http://www.sqlservercentral.com/articles/62867/[/url]

    Make sure you understand what this code is doing and not just blindly use it.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (9/17/2013)


    When something is really urgent it would benefit you to provide more details. Doing this quickly is going to depend on your meaning of quickly. Certainly using a while loop for 10,000,000 inserts is going to be horrendously slow.

    You could use a tally table and it will be a lot faster. This took about 43 seconds on my machine.

    WITH

    E1(N) AS (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))dt(n)),

    E2(N) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows

    E4(N) AS (SELECT 1 FROM E2 a, E2 b), --10E+4 or 10,000 rows max

    E5(N) as (SELECT 1 from E4 a, E4 b),

    cteTally(N) AS

    (

    SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E5

    )

    insert tmp

    select '1521' + right(REPLICATE('0', 6) + CAST(N - 1 as varchar(10)), 7)

    from cteTally

    where N <= 10000000

    You should read up on them here. http://www.sqlservercentral.com/articles/62867/[/url]

    Make sure you understand what this code is doing and not just blindly use it.

    thanks for the query.. works well.. but i could not understand what is happening ...

    surely will try to understand ..

  • vignesh.ms (9/17/2013)


    this is very urgent somebody help...

    In addition to Sean's comment - you also help yourself by using a more descriptive subject line for your post. I've noticed that you've posted a couple of "Help On Query" lately, it's difficult to tell whether it is a new one, or an old one.

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]

  • Erland Sommarskog (9/17/2013)


    vignesh.ms (9/17/2013)


    this is very urgent somebody help...

    In addition to Sean's comment - you also help yourself by using a more descriptive subject line for your post. I've noticed that you've posted a couple of "Help On Query" lately, it's difficult to tell whether it is a new one, or an old one.

    Sure will follow...

    Thanks your suggestions ...

Viewing 6 posts - 1 through 5 (of 5 total)

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