Procedure or function 'sp_***' expects parameter '#', which was not supplied - sql

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

Related

stored Procedure returning issues

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?

Can I have the same stored procedure with two different name?

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.

How to pass multiple values in place of single value to a stored procedure

I have a stored procedure, and it is executed perfectly, when i am using:
exec spSampleAmount 12212,0
Now i need to pass like "12212,12213,12214,12215" and these values coming from another query. How to pass this query result to a 2 argument stored proc.
exec spSampleAmount param1,param2;
param1 have set of values.
Store the output of first query in parameter. First declare the parameter and then assign the value of first query to that parameter then call exec command to execure the stored procedure.
DECLARE #V_Param1 VARCHAR(1000);
SELECT #V_Param1 = Rest of query
EXEC spSampleAmount #V_Param1, 0
if it is called by SSRS it's possible, i don't know exactly how it works, but it is.
You have 2 ways to call a stored procedure from ssrs, sql query and write execute. Or select execute stored procedure.
In that way you have the possibility to pass a selection from a multiple item selection combobox to the stored procedure and in your stored procedure do a : where myparam in (#paramreceived).
It should be also possible in .Net.
I tried to do that in tsql and i never succeeded, so i'm interrested too if there is a solution to that problem

Can't execute stored procedure

I have created a stored procedure and can see it under the stored procedure node, but when trying to execute it doesn't find the procedure.
Under stored procedure node it is called dbo.CopyTable
exec CopyTable
CopyTable is undefined in red saying it does not exist. Why?
Even if I right-click on the procedure and say script stored procedure as execute to - the code it generates is underlined in red and cant find stored procedure either.
Ensure that the database selected contains the stored procedure CopyTable
USE YourDatabase
EXEC CopyTable
Try adding dbo and selecting the right database,
USE databaseName
GO
EXEC dbo.CopyTable
GO
Execute a Stored Procedure
Most likely you are just in the wrong database in the query window, you can specify the database like this:
EXEC [yourDBName].dbo.CopyTable
Reading on how to Execute a Stored Procedure
Considering your updated question:
Even if i rightclick on the procedure and say script stored procedure
as execute to - the code it generates is underlined in red and cant
find stored procedure either.
This could happen if your stored procedure is invalid. Please double-check the validity of the SPROC and ensure the tables it references exist, etc.
Try running your CREATE PROCEDURE. Highlight it, f5 it, and then make sure it runs before you call it elsewhere.
Maybe in your procedure you've accidentally cut-pasted your script name (dbo.CopyTable), say something like...
SELECT * FROM dbo.CopyTable
WHERE ClientId = #ClientId
RETURN
Then when you call your proc you get 'invalid object name dbo.CopyTable' and assume sql is having trouble finding the stored-proc ... which isn't the problem, its finding and running the proc but its actually a problem within the proc.

Declaring stored procedures header and body separately

I'm writing stored procedures in SQL Server 2008. I need to create two procedures which will use each other.
Procedure A executes B and B executes A.
So I suppose I have to declare headers of procedures firstly. I've searched over internet but I can't find the answer how can I make it.
So, my question is: how can I declare header and body of stored procedure separately in SQL Server 2008?
You can't separate them but you can create a SP that calls another SP that not yet exist.
When you run this
create procedure TheFirst as
begin
exec TheSecond
end
and SP TheSecond does not exist you will get a message:
The module 'TheFirst' depends on the missing object 'TheSecond'. The
module will still be created; however, it cannot run successfully
until the object exists.
Update:
To avoid the messages you can first create an empty proc and add the code later in the script.
create procedure ProcB as
go
create procedure ProcA as
begin
exec ProcB
end
go
alter procedure ProcB as
begin
exec ProcA
end