Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Location
    Midlands
    Posts
    135

    Unanswered: How do I write an Update Stored Procedure?

    Hi all, how are you?

    I need some help with how to write a Stored procedure that updates a tbl within a database? I am new so please forgive the poor effort.

    Here are my stored procedure and table. Please shout if you need to know anything else

    TblStores2Zones
    column names (stores2zonesID - fkstoreID - fk_zoneID - Active)
    1 1 1 True
    2 1 2 True
    3 1 3 True
    4 1 4 True
    5 1 5 True

    Store procedure
    ALTER PROCEDURE [dbo].[spUpdateZones]
    @iStoreID DECIMAL
    @ifk_storeID INT
    @ifk_zoneID INT
    AS
    BEGIN
    SET NOCOUNT ON
    IF EXISTS(SELECT fk_storeID FROM tblstores2zones WHERE fk_storeID = @ifk_storeID )
    BEGIN
    UPDATE
    tblStores2Zones
    SET
    fk_storeID = @ifk_storeID
    fk_zoneID = @ifk_zoneID
    WHERE
    storeID = @iStoreID
    END

    END

    keep getting errors with this effort

    help is most welcome all

    Regard
    MG

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    you're missing commas in the update?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Jun 2009
    Location
    Midlands
    Posts
    135
    changed to this, and it executes....

    ALTER PROCEDURE [dbo].[spUpdateZones]
    (
    @iStoreID DECIMAL,
    @ifk_storeID INT,
    @ifk_zoneID INT
    )
    AS
    SET NOCOUNT ON
    BEGIN
    IF EXISTS(SELECT fk_storeID FROM tblstores2zones WHERE fk_storeID = @ifk_storeID )
    BEGIN
    UPDATE tblStores2Zones
    SET fk_storeID = @ifk_storeID,
    fk_zoneID = @ifk_zoneID
    WHERE fk_storeID = @iStoreID
    END

    END

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •