Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

How do edit stored procedure and save

I am running sql 2005 server.  I edited a stored procedure by Right clicking  dbo.usp_SelectAllProduct_NP  and selected "modify"

This allowed me to paste the additional code into the right hand window/pane, however when I try and save this it wants to save it a seperate file /query.    Is there something I don't understand?

am I not able to edit the original stored procedure? There must be a way to save my following stored procedure:

orginal stored procedure ====
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:            <Author,,Name>
-- Create date: <Create Date,,>
-- Description:      <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[usp_SelectAllProduct_NP]
AS
SELECT
     [P_ProductID],
     [P_ProductName],
     [P_QtyPerUnit],
     [P_UnitPrice],
     [P_UnitsInStock],
     [P_UnitsOnOrder],
     [P_ReorderLevel],
     [P_WareHouseNo],
     [P_ModifiedDate],
     [P_MEMO],
     [P_Desc]
FROM
     [dbo].[Products]


My modified stored procedure =====
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO


--region [dbo].[usp_SelectProductsAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   pateln using CodeSmith 3.2.6.887
-- Template:       StoredProcedures.cst
-- Procedure Name: [dbo].[usp_SelectProductsAll]
-- Date Generated: Thursday, June 29, 2006
------------------------------------------------------------------------------------------------------------------------

ALTER PROCEDURE [dbo].[usp_SelectProductsAll]
         
          @direction as nchar(20)
       
AS
     
DECLARE @SQL VARCHAR(4000)
     

SET @SQL = '
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT
     [P_ProductID],
     [P_ProductName],
     [P_QtyPerUnit],
     [P_UnitPrice],
     [P_UnitsInStock],
     [P_UnitsOnOrder],
     [P_ReorderLevel],
     [P_WareHouseNo],
     [P_ModifiedDate],
     [P_MEMO],
     [P_Desc]
FROM
     [dbo].[Products]
     order by ' + @direction

EXEC(@SQL)

--endregion

thanks
Nick

0
countyprob
Asked:
countyprob
1 Solution
 
NightmanCTOCommented:
After you have modified the stored procedure, simply run the query against the database - that will update it. press F5 to run the query
0
 
QPRCommented:
When you click save you are saving the code as a text file that you can run at a later date.
When you run the query (as Nightman says) you are running the script to ALTER the procedure. You aren't actually running the stored procedure at this stage.
0
 
countyprobAuthor Commented:
I guess they must do it that way to check syntax, right?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now