Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trouble Pass Date Parameter to Stored Procedure

Posted on 2014-01-27
1
Medium Priority
?
1,986 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 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

718 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