Solved

Modifiying an SP

Posted on 2009-05-17
10
219 Views
Last Modified: 2012-05-07
This is embarrassing to type - I am sure I must be missing something obvious.
In sql 2000 when I wanted to modify an sp (and was feeling lazy) I would right click it (EM) , choose properties alter the text and execute it.

I want to alter a SP in 2005 so I right click (SSMS) and choose modify.
First thing I notice is that the actual SP itself is in quotes and is a parameter for dbo.sp_executesql
So (inside the quotes) I make my change. Very simple, all I need to do is add an oder by.
I run it and all seems fine, but the data is not ordered by anything. I revisit the SP (modify) and my changes are gone.
If I re-type the changes and run the alter SP statement by itself then all is fine.

What is the purpose of this right click modify command if it's not going to make/save my changes?
0
Comment
Question by:QPR
  • 6
  • 3
10 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
Comment Utility
>So (inside the quotes) I make my change
once you made your changes, you have to complile that sp by pressing F5, otherwise the changes made on the sp wont remain there. I hope you missed to do that
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
I click "execute"
Command(s) completed successfully.

I close the window and am asked if I want to save sqlquery01.sql and I say no.
I reopen the SP and my changes are not there.
0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
are you reopening the sp through management studio?  can you post the code that you're running to alter your proc?  
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
yes everything via SSMS
In the example below, I can delete order by id desc.
Then I will execute and it will say all good.
I run the SP (from the web front end) and the order by will still be in effect.
Go back to SSMS and the orderby is still part of the sql


USE [Intranet]

GO

/****** Object:  StoredProcedure [dbo].[GetCDEMannounce]    Script Date: 05/18/2009 10:15:14 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCDEMannounce]') AND type in (N'P', N'PC'))

BEGIN

EXEC dbo.sp_executesql @statement = N'ALTER procedure [dbo].[GetCDEMannounce]

as

select FullItem

from dbo.CDEMAnnounce

where StartDate <= getDate()--dateadd(d,-1,getDate())

	and ExpireDate > getDate()

order by id desc' 

END

GO

GRANT EXECUTE ON [dbo].[GetCDEMannounce] TO [public]

Open in new window

0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
run this instead.

ALTER procedure [dbo].[GetCDEMannounce]
as
select FullItem
from dbo.CDEMAnnounce
where StartDate <= getDate()--dateadd(d,-1,getDate())
      and ExpireDate > getDate()
order by id desc

GO
GRANT EXECUTE ON [dbo].[GetCDEMannounce] TO [public]

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 29

Author Comment

by:QPR
Comment Utility
yep, I do... by ignoring all the other text in the modify dialogue and just selecting/running the actual alter procedure statement.

But why?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
Comment Utility
because that is how it should be done...I wish I knew why MS decided it was a better idea to generate dynamic SQL when you use an IF object exists clause...you can go to tools, options, and turn that option off.  If you don't use the option to drop the object if it exists, it doesn't use the dynamic sql
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
Can I clarify unless I'm missing something...
I navigate to the SP in SSMS, right click and choose modify.
Amend the text and then execute. Get the message that the command ran successfully.
But in reality the changes were not made/saved and the changed have not propogated to the DB?
0
 
LVL 29

Author Comment

by:QPR
Comment Utility
sorry the "but why" was not directed at your uiggestion, it was directed at why would MS give me this "modify" option that doesn't appear to work.
0
 
LVL 29

Author Closing Comment

by:QPR
Comment Utility
that works (changing the options) thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now