Solved

How do edit stored procedure and save

Posted on 2006-11-27
3
241 Views
Last Modified: 2008-02-01
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
Comment
Question by:countyprob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 18022723
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
 
LVL 29

Expert Comment

by:QPR
ID: 18022811
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
 
LVL 1

Author Comment

by:countyprob
ID: 18022852
I guess they must do it that way to check syntax, right?
0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 to SQL Server 2016 24 57
Remove () 10 41
Replace statements HTML with HTML IF 8 66
Migrate SQL 2005 DB to SQL 2016 4 32
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question