Solved

Trouble Pass Date Parameter to Stored Procedure

Posted on 2014-01-27
1
1,861 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 143

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

828 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