|
-
Jun 26th, 2003, 03:30 AM
#1
Thread Starter
Lively Member
Stored Procedure Null Vlaues
Hi!
I get an error when a send a null datetime and integer values to a stored procedure.
Error:
Application uses a value of the wrong type for the current operation.
cmdNP_AQUA.Parameters.Append cmdNP_AQUA.CreateParameter("@effective_to", adDate + adEmpty, adParamInput, 8, rsNP_ESERVER("effective_to")))
cmdNP_AQUA.Execute
Is there a way to send null values to a stored procedure?
-
Jun 26th, 2003, 04:18 AM
#2
Fanatic Member
it's best not to have null values in a database. Put blank times in for datetime such as "00:00:00" and may be 0's for integers.
-
Jun 26th, 2003, 10:30 AM
#3
Is there a way to send null values to a stored procedure?
Absolutely. I do it all the time. The only possible problem that I see with the code you posted is the datatype paramter. Note the size parameter is only required for variable length columns.
Change adDate + adEmpty to just adDBTimeStamp
-
Jun 26th, 2003, 11:02 AM
#4
The value for a "NULL" date (which a contradiction as you can't have a non date) is to use "12/31/1899". SQL Server will treat that value as similarto NULL.
-
Jun 26th, 2003, 11:12 AM
#5
Any variable in SQL Server, which is what we are talking about here, can be set to Null. Even dates. In fact all variables are initialzed to Null when they are declared.
-
Jul 2nd, 2003, 08:32 AM
#6
Junior Member
Response
Not sure why you would want a date nullable. Have you thought about setting the date as a default value, i.e getdate(). Or just use the other strategies provided in this thread. Also if you want to add null or if a user doesn't enter a value this is how it's done
@DummyVar AS VARCHAR(10) = NULL /* This makes the parameter value optional */
Just throw an If condition such as
IF @DummyVar IS NOT NULL
BEGIN
IF RTRIM(@SQL) <> '' SET @SQL = @SQL + ',' + RTRIM (@DummyVar) + ' FROM TBLSample '
END
Hope this helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|