Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating SQL Server Stored Proc in VB

Status
Not open for further replies.

Longia

Programmer
Dec 8, 2000
23
US
Hello Everybody

Need to know if I can create stored procedure from vb code. I need this because number of parameters in stored proc is not fixed, it varies as per my logic and every time I run my program I need different parameters so is there a way to create stored proc from VB program and drop it later.

Thx
 
You can do this by executing the following sql
"create procedure sp_proc1 (@param1 int) As
select * from mytable"

or to drop the sp "drop procedure sp_proc1"

However Im sure this is not good practice and somewhat defeats the purpose of using stored procedures. There must be better ways to achieve what you want, could you not just set the parameters as optional and only pass the ones you need each time ?

cjw
 
Hi,

You can make a parameter optional by adding a value to the definition:
--------------------------------------
Create procedure UP_MyStoredProc
@ID int,
@Hits int = NULL output
as ....
--------------------------------------
In this case it is an optional output parameter, but it work in the same way with input parameters.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top