Solved

Trouble Pass Date Parameter to Stored Procedure

Posted on 2014-01-27
1
1,799 Views
Last Modified: 2014-01-28
Hi Everyone,

I am currently working with a stored procedure that will update old or insert new values into a database table. It passes in 8 values in total and seven of them work  correctly. But I have one parameter that I am passing in (a date parameter) that is not working correctly. Everytime I go to save the entries, it blanks out the date field whether it is an insert or an update. When I go back to query the database all it leaves is a null entry for that date field that I want to enter the value into.

Here is some of the code for the procedure:

CREATE PROCEDURE [StudentTrax].[sp_wo_adm_set_teval_data]
@p_pidm int, @p_college_name varchar(255), @p_degree varchar(10), @p_grad_date datetime, @p_credits_attempted numeric(5, 2), @p_ld_credits numeric(5, 2), @p_ud_credits numeric(5, 2), @p_grade_points numeric(5, 2), @p_user_id varchar(255), @p_term_code varchar(7)

And here is the code I call it with: (Note: the numbers are text boxes and 647 is the text box that is supposed to send up the date):

exec sp_wo_adm_set_teval_data('?', ':625:', ':646:', ':647:', ':648:', ':649:', ':650:', ':651:', ':USERNAME:', ':689:')

Another thing I was wondering is if I could possibly use something to convert a string value to a date using the parameter 647

Thank You
0
Comment
Question by:johnnypoi
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39813357
I recommend you read up this article:
http://www.experts-exchange.com/Database/Miscellaneous/A_1499-DATE-and-TIME-don%27t-be-scared-and-do-it-right-the-first-time.html

so, in your case, as the "input" is coming from a text box, you are running into implicit data type conversion.

you actually do have only 2 options:
* instead of a text-box, have a date-input control (calendar control or the like), or convert the user input from the text box (string) to datetime before passing to the stored procedure

* modify the stored procedure data type for the parameter from date to varchar, and handle the conversion inside the procedure (using the convert function with the "style" value which matches your environment or your user(s) specifically

hope this helps
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now