create procedure

  • hi guys

    my sql code so

    delete from numbers

    declare @i as int

    set @i = 3440000

    while(@i < 3442047)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=3440000 and phone<=3442047

    )

    query works fine

    and

    Results 144 query strings

    3442047 changed to @ t1

    and created a procedure

    create alter proc trt

    @i int,

    @t1 int

    as

    delete from numbers

    while(@i < @t1)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=@i and phone<=@t1

    )

    exec dbo.trt @i=3440000,@t1=3442047

    but Results this query

    2047 lines

    means a procedure does not work

    this script

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=@i and phone<=@t1

    )

    someone can advise how I can change this procedure?

    To have a good Results

    thank's

  • gurbanov.1984 (4/21/2014)


    hi guys

    my sql code so

    delete from numbers

    declare @i as int

    set @i = 3440000

    while(@i < 3442047)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=3440000 and phone<=3442047

    )

    query works fine

    and

    Results 144 query strings

    3442047 changed to @ t1

    and created a procedure

    create alter proc trt

    @i int,

    @t1 int

    as

    delete from numbers

    while(@i < @t1)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=@i and phone<=@t1

    )

    exec dbo.trt @i=3440000,@t1=3442047

    but Results this query

    2047 lines

    means a procedure does not work

    this script

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=@i and phone<=@t1

    )

    someone can advise how I can change this procedure?

    To have a good Results

    thank's

    Can you please provide more inputs like DML of tables used number of records in each tables and few sample records.

    --rhythmk
    ------------------------------------------------------------------
    To post your question use below link

    https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
    🙂

  • Friend

    1st I delete the table numbers

    2 nd inserted number to table numbers with cycle

    while(@i < 3442047)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    3rd select the number from the table

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=3440000 and phone<=3442047

    )

    and change here at 3440000 @ i and 3442047 @ t1 on

    and created this procedure

    create alter proc trt

    @i int,

    @t1 int

    as

    delete from numbers

    while(@i < @t1)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=@i and phone<=@t1

    )

    but here it is not true I do not know but the result is incorrect

  • You deleted records from the numbers table, but your filter is being applied to the phone table. How many records are in the phone table in your first test (query execution) compared to your second test (stored procedure call)? This is likely why you are seeing different results.

    Shawn Melton
    Twitter: @wsmelton
    Blog: wsmelton.github.com
    Github: wsmelton

  • I changed the structure of the procedure

    so

    created a new parameter @ t2

    now works good

    Results and got what I want

    alter proc trt

    @t1 int,

    @t2 int

    as

    delete from numbers

    declare @i int

    set @i=@t1

    while(@i <@t2)

    begin

    insert into numbers values(@i)

    set @i = @i+1

    end

    select ph from numbers where ph not in(

    select phone from

    phone where phone >=@t1 and phone<=@t2

    )

    thank?s all

    my friends

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

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