creating stored procedure

  • hello,

    i am a new and beginner in using sql server 2005 and creating a stored procedure. I have created a new procedure but i don't understand this. could someone give me an example on how to create a procedure using this code below.

    CREATE PROCEDURE <'Procedure_Name, sysname, ProcedureName'>

    -- Add the parameters for the stored procedure here

    <@Param1, sysname, @p1> <'Datatype_For_Param1', , int> = <'Default_Value_For_Param1', , 0>,

    <@Param2, sysname, @p2> <'Datatype_For_Param2', , int> = <'Default_Value_For_Param2', , 0>

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    -- Insert statements for procedure here

    SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>

    END

    GO

    by the way, i just put the single quotation mark to display the data inside it.

    hoping any response from you guys...

  • I see you're using the templates.  Note that they are just samples, and there's plenty of room for you to modify them for your needs.  This stored procedure template sets up a basic procedure (that actually does nothing) with two input parameters. 

    When using those templates, you fill in the "<@Param1, sysname, @p1> "  stuff by hitting [ctrl]+[shift]+M.  That will bring up a dialog box asking you for the procedure name (will default to "Procedure Name"), a name for the first parameter (defaults to "@p1"), its datatype (defaults to "int") and default value (default 0), the second parameter (default "@p2"), it's type (int), and default (0).

    Click 'OK'  or 'Replace' and the odd text will be replaced with your entries.  You will then have a procedure stub ready for your code.  First, you can adjust the parameters - you can take one or both of them out, or add more, or change the datatypes, etc.  You can get rid of the SELECT statement.

    After that, the space between BEGIN and END is ripe for your code.  (Actually, the BEGIN and END are optional too, but they help clarify things to anyone else reading it...)  If you are new to this, then tradition dictates that your first procedure should look something like the following:

    CREATE PROC dbo.HelloWorld
    AS
    BEGIN
    SET NOCOUNT ON;
      SELECT 'Hello World!' AS [MyMessage]
    
    END
    GO

     

    -Eddie

    Eddie Wuerch
    MCM: SQL

  • thank you for very for taking the time to answer my query.

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

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