Results 1 to 7 of 7
  1. #1
    Join Date
    May 2003
    Posts
    22

    Unanswered: Stored Procedure questions...

    I am trying to set up my first SPROC and I want to combine my normal 3 step process into 1 SPROC.

    step 1) Select * from table where field ='string';

    step 2) Insert from table1 into table 2.....

    step 3) Delete from table1 where ....



    How do I sequence the 3 SQL statements into 1 SPROC?

    SPROC = stored Procedure (not sure if sproc is common name)


    thanks in advance oh SQL server gurus'

    JDF

  2. #2
    Join Date
    Sep 2003
    Location
    New York, NY
    Posts
    136
    CREATE Procedure dbo.sp_SPROC as
    Select * from table where field ='string'
    Insert from table1 into table 2.....
    Delete from table1 where ....
    go
    Last edited by rohitkumar; 12-01-03 at 17:34.

  3. #3
    Join Date
    May 2003
    Posts
    22
    return carraige is it? all I need to do is type tyhe next sql statement on a new line?

    no need for brackets/braces/nested statements etc.?

    thanks..

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Yup,

    But if you want you can use a semicolon..though I don't think I've seen that style...it's a DB2ism..

    Code:
    USE Northwind
    GO
    
    CREATE PROC myProc
    AS
    BEGIN TRAN;
    SELECT * FROM Orders;
    INSERT INTO Orders (Freight) SELECT 9999;
    DELETE FROM Orders WHERE OrderId = 9999;
    ROLLBACK TRAN; 
    GO
    
    EXEC myProc
    GO
    
    DROP PROC myProc
    GO
    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.

  5. #5
    Join Date
    May 2003
    Posts
    22

    thanks a million

    Every time I hear someone say "people dont help people anymore" I tell em to check the studs @ DBFORUMS....rock on people!!!!!

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322

    Re: thanks a million

    Originally posted by jfouse
    Every time I hear someone say "people dont help people anymore" I tell em to check the studs @ DBFORUMS....rock on people!!!!!
    Well....

    Check out this then....

    http://www.sqlteam.com/default.asp

    Happy coding...

    And remeber, it's not a matter of if...it's a matter of when....
    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.

  7. #7
    Join Date
    Sep 2003
    Location
    New York, NY
    Posts
    136
    if you're using, if condition or while condition do like...

    if a>b
    begin
    .....
    .....
    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
  •