Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript: Passing a parameter with a null value to a stored procedure?

In VBScript (ASP environment), is it possible to pass a parameter with a null value to a stored procedure?

like image 408
burnt1ce Avatar asked Jul 21 '09 15:07

burnt1ce


People also ask

How to pass NULL value in Store procedure?

Set the defaults to NULL in the proc and you dont have to explicity pass NULL to a proc. CREATE PROC .. dbo. Proc ( @param1 int =NULL, @param2 varchar(40) = NULL ...)

What does NULL mean in SQL?

A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. Note: A NULL value is different from a zero value or a field that contains spaces.


1 Answers

Passing null to a stored procedure, using a command object.

Set cn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Data Source=.\Test"
Set cmd.ActiveConnection = cn
cmd.CommandText = "TestTable.sp_ModifyData"
cmd.CommandType = 4
cmd.NamedParameters = True

set cnParam = cmd.CreateParameter("@RowID",3,3,,-1)
cmd.Parameters.Append cnParam
set cnParam = cmd.CreateParameter("@AddRemoveModify",3,1,,0)
cmd.Parameters.Append cnParam
set cnParam = cmd.CreateParameter("@Value1",3,1,,0)
cmd.Parameters.Append cnParam
set cnParam = cmd.CreateParameter("@Value2",8,1,-1,"Test")
cmd.Parameters.Append cnParam
set cnParam = cmd.CreateParameter("@value3",5,1,,null)
cmd.Parameters.Append cnParam
set cnParam = cmd.CreateParameter("@value4",5,1,,0)
cmd.Parameters.Append cnParam
set cnParam = cmd.CreateParameter("@value5",8,1,-1,"")
cmd.Parameters.Append cnParam
cmd.Execute
cn.Close
Set cmd = Nothing
Set cn = Nothing

Sorry I didn't put much thought into naming the fields in my database.

like image 163
Tester101 Avatar answered Sep 19 '22 08:09

Tester101