sql stored proc does not process input variables correctly

  • Hi, newbie here. Having a weird problem with sql stored proc. I have this generic proc I wrote to intake a fieldname and a table name and process it for invalid data. problem is at runtime it does the opposite. Its never happened before and I am wondering if its a problem in T-SQL or my code. Here is my code. Any help would be appreciated.

    CREATE procedure [dbo].[prc_de_yn_generic_ced] @field_name varchar(30),

    @table_name varchar(50)

    as

    declare @countint

    declare @d_code varchar(500)

    SET @d_code = (Select dcode from t1 where field_name = @field_name)

    If @table_name = 'tw_STK_Import'

    begin

    set @count = (select count(*) from tw_STK_Import)

    IF @count != 0

    BEGIN

    Insert into tw_STK_msr_error

    select*, @derc_code

    fromtw_STK_Import

    where--atrl_fib_flttr_cd

    @field_nameis NOT NULL

    AND ltrim(rtrim(@field_name)) <> ''

    ANDltrim(rtrim(@field_name)) not in ('Y', 'N')

  • svenk7 (9/25/2009)


    CREATE procedure [dbo].[prc_de_yn_generic_ced] @field_name varchar(30),

    @table_name varchar(50)

    as

    declare @countint

    declare @d_code varchar(500)

    SET @d_code = (Select dcode from t1 where field_name = @field_name)

    If @table_name = 'tw_STK_Import'

    begin

    set @count = (select count(*) from tw_STK_Import)

    IF @count != 0

    BEGIN

    Insert into tw_STK_msr_error

    select*, @derc_code

    fromtw_STK_Import

    where--atrl_fib_flttr_cd

    @field_nameis NOT NULL

    AND ltrim(rtrim(@field_name)) ''

    ANDltrim(rtrim(@field_name)) not in ('Y', 'N')

    First this statement compiled completely with out an error?

    Show complete SP.

    And try this

    CREATE procedure [dbo].[prc_de_yn_generic_ced]

    @field_name varchar(30),

    @table_name varchar(50)

    as

    BEGIN--01

    declare @count int

    declare @d_code varchar(500)

    Select @d_code = dcode

    from t1

    where field_name = @field_name

    If (@table_name = 'tw_STK_Import')

    BEGIN--02

    select @count = count(*)

    from tw_STK_Import

    END--02

    IF (@count != 0)

    BEGIN--03

    Insert into tw_STK_msr_error

    select *, @d_code

    from tw_STK_Import

    where --atrl_fib_flttr_cd

    @field_name is NOT NULL

    AND ltrim(rtrim(@field_name)) not in ('','Y', 'N')

    END--03

    END--01

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

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