We have a stored procedure spLocal_CmnUI_BMGetLatestBiasRecords.
When we execute the stored procedure manually using Declare statement then it returns correctly. However, when we execute the stored procedure by using Exec stored procedure it returns invalid results.
Any idea what could be the problem?
Related
Bellow, I have a stored procedure named usp_customer
CREATE PROCEDURE usp_customer
AS
BEGIN
SELECT * FROM CUSTOMER
END
I want to give the same exact stored procedure a second name usp_cust1
Note: I am not looking to rename or to create a new stored procedure, I want both names to work
In the end, I could use either EXEC usp_customer or EXEC usp_cust1
Thanks
edit: changed sp_ to usp_
One stored procedure can call another:
CREATE PROCEDURE usp_cust1
AS
BEGIN
EXEC usp_customer;
END;
Note that in SQL Server, you should not use the "sp_" prefix for stored procedures. That is best reserved only for system stored procedures.
I have stored procedures in vb.net app. Once I call the stored procedure with parameters, the other stored procedure with no parameters throw exceptions "Procedure has no parameters and arguments were supplied."
Check your function if it's calling the right name of the stored procedure and has correct parameter/s
Ok. I got it. It have to clear the stored procedure's sqlcommand
sqlcommand.Parameters.Clear()
before execute the another stored procedure without parameters.
create procedure spGoti
#WeekNumber nvarchar(255)
as
begin
execute spPointsUpdate #WeekNumber
execute spGivebadges #WeekNumber
execute spLevelField #WeekNumber
execute spAddNewWeekDataToTotalOfEmployeeTable #WeekNumber
execute spTop15Overall
execute spWeeklytop15 #WeekNumber
end
in the above code I have written stored procedures within stored procedures.
I have a peculiar problem here. The second stored procedure (spGivebadges #WeekNumber) uses the output of previous stored procedure (spPointsUpdate #WeekNumber).
The problem is if I execute the parent stored procedure i.e spGoti, then the second stored procedure spGivebadges #WeekNumber does not get executed . But when I run spGoti the second time, then the second stored procedure gets executed without any problem.
All the other stored procedures within the parent gets executed the first time itself, though some are using output of another.
Why is this happening?
the create script for the stored procedure is as follows.
CREATE PROCEDURE [dbo].[storedprocedure]
-- Add the parameters for the stored procedure here
#Mappings XML
AS
BEGIN
......
END
And I invoke it with
exec storedprocedure xmlparam.
The issue is that xmlparam is huge and each time I run the 'exec stored procedure xmlparam', sql server management studio freezes up for several minutes.
Is there a better way of doing this? I want to run the exec command through ssms as I wanna see the different record sets it spits out.
I am trying to execute a stored procedure but getting following error:
Procedure or function 'SP_DELETE_DESIGN_PARAMETERS' expects parameter '#DESIGN_ID', which was not supplied.
Below is my stored procedure.
I am trying to execute it in SQL need result in table.
CREATE PROCEDURE SP_DELETE_DESIGN_PARAMETERS
#DESIGN_ID INT
AS
BEGIN
Delete From Design_Parameters where Design_ID = #DESIGN_ID
END
exec SP_DELETE_DESIGN_PARAMETERS
I know I am missing some very easy points. I would appreciate any help into this.
I am using SQL Server 2008 R2 and VS2010 with VB.Net
Thanks :)
exec SP_DELETE_DESIGN_PARAMETERS #DESIGN_ID = 5
exec SP_DELETE_DESIGN_PARAMETERS 5
Read up on how to pass parameters to a stored procedure. You are asking for a parameter but not supplying it.
When you exec your stored procedure you need to pass it the #DESIGN_ID parameter it expects.
EXEC SP_DELETE_DESIGN_PARAMETERS 123
where 123 is the ID you want to pass to the stored procedure