insert and update issue

  • Hello all,

    Im experiencing something I have never had an issue with.

    I have a general insert update method. Below is a quick example of the code statements I am trying to execute.

    DECLARE @EXISTS

    a select statement that sets @EXISTS

    IF @EXISTS = 1

    BEGIN

    UPDATE METHOD HERE

    END

    IF @EXISTS =0

    BEGIN

    INSERT METHOD HERE

    END

    Im not exactly sure what is happening, but I know the statements are being hit. I put a SELECT 1 in the @EXISTS =1 method and a SELECT 0 in the @EXISTS = 0 method.

    I get the proper value back when I executescalar. 1 for update and 0 for insert.

    Im at a complete loss here. If I execute the proc in management studio and pass in the exact same values, it runs fine and does exactly as it should. However, it runs from my aspx page and does nothing. Doesnt throw any errors.

    Any help would be appreciated.

  • Are you sure you are passing in a value - paraphrasing your procedure

    CREATE PROC dbo.myproc

    @Exists INT

    AS

    IF @EXISTS = 1

    BEGIN

    PRINT 'UPDATE METHOD HERE'

    END

    IF @EXISTS =0

    BEGIN

    PRINT 'INSERT METHOD HERE'

    END

    dbo.myproc NULL -- imitating passing of a NULL value ... nothing will happen and no error will be reported.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • ive checked and rechecked passed in values.

    Im only passing in two ID's and four bit values from check boxes.

  • Use Sql Server Profiler and look what statement exactly passed to server to run.

    If it wouldn't help, write here your stored procedure and the statement from Sql Server Profiler.

    -------------------------
    - Name?
    - Abu Dalah Sarafi.
    - Sex?
    - 3 times a week!
    - No, no. Male or Female?
    - Male, female, sometimes camel...

  • Hi

    Try using OUTPUT keyword to find out whther its updating any records or not.

    CREATE TABLE EMPLOYEE_WORKING_HRS(

    EMP_ID int NULL,

    ENAME varchar(30) NULL,

    YR varchar(4) NULL,

    MON varchar(3) NULL,

    WORKING_HRS int NULL,

    RATE int NULL,

    SALARY AS (WORKING_HRS*RATE)

    )

    INSERT INTO EMPLOYEE_WORKING_HRS VALUES(100,'SAM',2009,'JAN',176,100);

    INSERT INTO EMPLOYEE_WORKING_HRS VALUES (101,'LIMO',2009,'JAN',176,110);

    INSERT INTO EMPLOYEE_WORKING_HRS VALUES(102,'NAT',2009,'JAN',176,120);

    INSERT INTO EMPLOYEE_WORKING_HRS VALUES (103,'BECK',2009,'JAN',176,130);

    declare @Emp_ids table(ID int)

    update EMPLOYEE_WORKING_HRS set RATE = RATE - 20

    output inserted.EMP_ID into @Emp_ids

    from EMPLOYEE_WORKING_HRS

    WHERE RATE > 100

    SELECT * FROM @Emp_ids

    Modify the above code and see if your UPDATE statement is having any problems!!

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

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