Solved

Trouble Pass Date Parameter to Stored Procedure

Posted on 2014-01-27
1
1,912 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

752 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