Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Not asking for any parameters in stored procedure Expand / Collapse
Author
Message
Posted Monday, July 15, 2013 1:21 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:35 AM
Points: 28, Visits: 78
I am creating a stored procedure to send an email when the status field in a table changes from Pending to Approved and eventid is the unique id for the events.
I am using update command to change the status and capturing oldstatus and newstatus.
But when I run the procedure, It is not asking for the parameters and when I execute it I am getting no result as it is not asking for any parameter

Please let me know what I am doing wrong.

Thanks,
Blyzzard

Below is the code:

declare @EventId int
declare @EventName nvarchar(500)
declare @EventDate datetime
declare @sstatus nvarchar(50)

declare @oldstatus nvarchar(50)
declare @newstatus nvarchar(50)

select @oldstatus=sstatus from tblEvents where EventID=@Eventid

UPDATE [tblEvents]
SET [EventName] = @EventName, [EventDate] = @EventDate,
[sstatus]= @sstatus, [Updateuser]=@Updateuser,UpdateDate=GetDate()

WHERE [EventID] = @Eventid
select @newstatus=sstatus from tblEvents where EventID=@eventid

--if oldstatus doesnot matches with newstatus then execute rest

if @oldstatus <> @newstatus

begin
*****rest of the code********
Post #1473865
Posted Monday, July 15, 2013 1:24 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:58 PM
Points: 3,637, Visits: 7,934
That's not the code for a Stored Procedure. If you have defaults assigned to the parameters, then the SP won't forrce you to input any parameter.


Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1473866
Posted Monday, July 15, 2013 1:31 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:35 AM
Points: 28, Visits: 78
How do I do this? I want to update the status to newstatus and comapre oldstatus and newstatus for a particular eventid and keep rest of the values same as stored.
Post #1473867
Posted Monday, July 15, 2013 2:00 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:58 PM
Points: 3,637, Visits: 7,934
Could you post the complete definition of the stored procedure?
try to use the IFCode located in the left when you write the post [ code="sql"][/code]



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1473886
Posted Monday, July 15, 2013 2:10 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:35 AM
Points: 28, Visits: 78
Basically tblevents has a field name sstatus and I am capturing oldstatus and then in the update statement if the status changes to newstatus and then comparing them




USE [databasename]
GO

/****** Object: StoredProcedure [dbo].[sp_Mail_UpdateEvents] Script Date: 07/15/2013 14:36:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



Create PROCEDURE [dbo].[sp_MailUpdateEvents]

AS
SET nocount ON


BEGIN TRY

declare @EventId int
declare @EventName nvarchar(500)
declare @EventDate datetime
declare @sstatus nvarchar(50)

declare @oldstatus nvarchar(50)
declare @newstatus nvarchar(50)

select @oldstatus=sstatus from tblEvents where EventID=@Eventid

--create TABLE #StatusChanges ( Status1 Varchar(20),Status2 VARCHAR(20));
UPDATE [tblEvents]
SET [EventName] = @EventName, [EventDate] = @EventDate,
[sstatus]= @sstatus, [Updateuser]=@Updateuser,UpdateDate=GetDate()

WHERE [EventID] = @Eventid
select @newstatus=sstatus from tblEvents where EventID=@eventid

--if oldstatus doesnot matches with newstatus then execute rest

if @oldstatus <> @newstatus


Post #1473889
Posted Monday, July 15, 2013 2:32 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:58 PM
Points: 3,637, Visits: 7,934
The problem is that you don't have any parameters declared. All you have are variables.

Without knowing more about your SP, this might help but you might want to remove parameters that should actually be variables (like @oldstatus).

Create  PROCEDURE [dbo].[sp_MailUpdateEvents]
(
@EventId int,
@EventName nvarchar(500),
@EventDate datetime,
@sstatus nvarchar(50)
)
AS
SET nocount ON


BEGIN TRY

declare @oldstatus nvarchar(50),
@newstatus nvarchar(50)

select @oldstatus=sstatus from tblEvents where EventID=@Eventid

--create TABLE #StatusChanges ( Status1 Varchar(20),Status2 VARCHAR(20));
UPDATE [tblEvents]
SET [EventName] = @EventName, [EventDate] = @EventDate,
[sstatus]= @sstatus, [Updateuser]=@Updateuser,UpdateDate=GetDate()

WHERE [EventID] = @Eventid
select @newstatus=sstatus from tblEvents where EventID=@eventid

--if oldstatus doesnot matches with newstatus then execute rest

if @oldstatus <> @newstatus






Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1473898
Posted Monday, July 15, 2013 2:37 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:12 PM
Points: 13,441, Visits: 12,303
As I read this a few times I keep asking myself...is this person trying to implement a trigger? You said you use this when a certain value changes, how do you call this procedure? Why do you not pass it any parameters? Would this make sense to have in a trigger instead of a proc?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1473899
Posted Monday, July 15, 2013 8:38 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:35 AM
Points: 28, Visits: 78
Thanks a lot .. It worked
Post #1473954
Posted Monday, July 15, 2013 9:08 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 7:35 AM
Points: 28, Visits: 78
Sean, do you mean same code but instead of calling sp just fore trigger when the value changes?
Please bear with me as I am a newbie.

Thanks
Post #1473958
Posted Tuesday, July 16, 2013 6:20 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 3:27 AM
Points: 1,890, Visits: 2,329
Your stored procedure was executing as you didn't specify any parameters in that sp...
Please refer Luis post...



_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1474087
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse