Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Regarding stored procedure


Regarding stored procedure

Author
Message
boobalanmca07
boobalanmca07
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 14
I am using two sql statements in stored procedure,
the two sql query is update and alter.
in some times i need to execute update query only,at that time how to execute stored procedure
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14958 Visits: 38972
boobalanmca07 (11/27/2012)
I am using two sql statements in stored procedure,
the two sql query is update and alter.
in some times i need to execute update query only,at that time how to execute stored procedure



ALTER? to alter a table, it would only need to occur once, ever, in the database; doesn't really belong in the procedure.
otherwise you end up having to test every time whether to do it or not, which, since it will occur once, wastes a little bit of time checking to see if it needs to be done.


so my advice is to rethink where to put the alter statement...i don't think it belongs in a procedure.

regardless, you'd have to do something like this:

CREATE PROCEDURE MyProc(@paramters int)
AS
BEGIN
IF NOT EXISTS (SELECT 1
from sys.objects objz
left outer join sys.columns colz
on objz.object_id = colz.objectid
where objz.name = 'MyTable'
and colz. name = 'MyColumn')
BEGIN --IF
ALTER TABLE MyTable ADD MyColumn sqlvariant
END --IF

UPDATE MyTable
SET SomeColumn = SomeValue
WHere AnotherColumn = @paramters
END --PROC



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 5478
Could you please post your stored procedure code?
Without seeing what you can see it's hard to provide relevant help. Please read an article from the link at the bottom of my signature about this forum etiquette.

From your very vague description, I can only guess that you have to choices:

1. Create a separate stored proc which only performs UPDATE
2. Amend the existing one to have input parameter as a flag which will determine its behaviour.

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
I'd need to see the proc to be able to help out here.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3042 Visits: 5478
Instead of including the code here, OP just duplicated the post:

http://www.sqlservercentral.com/Forums/Topic1389161-149-1.aspx

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search