SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Not asking for any parameters in stored procedure


Not asking for any parameters in stored procedure

Author
Message
amar_kaur16
amar_kaur16
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 178
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********
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16331 Visits: 19073
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.
General Disclaimer:
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?


How to post data/code on a forum to get the best help: Option 1 / Option 2
amar_kaur16
amar_kaur16
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 178
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.
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16331 Visits: 19073
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.
General Disclaimer:
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?


How to post data/code on a forum to get the best help: Option 1 / Option 2
amar_kaur16
amar_kaur16
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 178
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



Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16331 Visits: 19073
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.
General Disclaimer:
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?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25902 Visits: 17518
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 Modens 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)
amar_kaur16
amar_kaur16
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 178
Thanks a lot .. It worked
amar_kaur16
amar_kaur16
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 178
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
kapil_kk
kapil_kk
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3057 Visits: 2766
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/
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