Loop won''t terminate

  • Thanks for the replies,

    Let me try and clear some things up:

    1.  the whole reason i started this thread was because i was trying to write a one time import routine that would be thrown away.

    2.  generally when i write data logic, i place the logic in stored procedures.  I often will run a check on an input parameter before executing another stored procedure or Insert / Update / Select statement.

    How do you call one stored procedure from another without writing "bad code"?

    Do you guys consider it wrong to write code like:

    Declare @value1 as int

    Select @Value1 = @Column1 From Table1

    IF @Value1 is > 0

    begin

         Exec stored_Procedure1 @Value1=@Value1

    end

    ELSE

    begin

         Exec stored_Procedure2

    end

    .

  • >>Do you guys consider it wrong to write code like:

    Declare @value1 as int

    Select @Value1 = @Column1 From Table1

    IF @Value1 is > 0

    begin

         Exec stored_Procedure1 @Value1=@Value1

    end

    ELSE

    begin

         Exec stored_Procedure2

    end

    . <<

    Oh yeah! that's to ask for trouble if it grows!

    For instance: Suppose user1 and user2 are calling your procedure at once and let's assume stored_procedure1 changes the value of column1. when the select statement is called both are receiving the same value (supposed = 1) then one of them changes through the sp the value and the other is still going to call the stored procedure inspite of the value being different now

     I hope it was not too difficult to understand

    Cheers

     


    * Noel

  • As Noel implied, to ensure the value selected does not change between the time it is read and the time it is acted on, you would need to be within a transaction and do the SELECT using with (Holdlock) or with (Updlock).

    Edit: More to the point.  These issues/problems can and should be avoided (as mentioned) with a well crafted SQL statement.

    P.S.  It was beautiful the day someone came to me and said it looks like my procedue was not working correctly and I replied I don't know how that can be as there is not one line of procedural code (to screw up) it's all one update statement and I can prove it works. 

     

Viewing 3 posts - 16 through 17 (of 17 total)

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