Solved

Trouble Pass Date Parameter to Stored Procedure

Posted on 2014-01-27
1
1,775 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
Comment Utility
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Updating variable table 9 16
separate column 24 19
IN with @variable 5 16
scheduling a stored procedure in azue sql server 3 14
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

744 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

20 Experts available now in Live!

Get 1:1 Help Now