UPDATE dtb140_works
SET work_start = @work_start_date + ' ' + @work_start_time
WHERE (work_id = @work_id)
Main Topics
Browse All TopicsDear Experts,
I'm trying to create a stored procedure to update a datetime field from 2 input parameters. (The reason it's like this is that I want to enter the start date/time simular to setting an Outlook reminder, where you have a Calendar Selector for the date and a Combo for the Time)
Below is the syntax:
ALTER PROCEDURE dbo.dsp_update_works
(
@work_id int,
@work_start_date varchar,
@work_start_time varchar
)
AS
UPDATE dtb140_works
SET work_start = CONVERT(nvarchar(50), @work_start_date, 106) + ' ' + CONVERT(nvarchar(50), @work_start_time, 108)
WHERE (work_id = @work_id)
IF @@ERROR <> 0
BEGIN
RAISERROR ('Update Works failed.',18,1)
RETURN
END
When I run the sql it works ok. However, when I run it as a Store Procedure it errors with the following error:
Running [dbo].[dsp_update_works] ( @work_id = 2956, @work_start_date = 17/8/06, @work_start_time = 14:00:00 ).
Conversion failed when converting datetime from character string.
No rows affected.
(0 row(s) returned)
@RETURN_VALUE =
Finished running [dbo].[dsp_update_works].
I've tried various alternatives in variables, but with no success, can someone please tell me what I'm doing wrong?
Many Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I've tried that and it still doesn't work.
Amending the SP to the below:
ALTER PROCEDURE dbo.dsp_update_works
(
@work_id int,
@work_start_time varchar,
@work_start_date varchar
)
AS
UPDATE dtb140_works
SET work_start =@work_start_date + ' ' + @work_start_time
WHERE (work_id = @work_id)
IF @@ERROR <> 0
BEGIN
RAISERROR ('Update Works failed.',18,1)
RETURN
END
Gives the following Error:
Running [dbo].[dsp_update_works] ( @work_id = 2956, @work_start_time = 14:00, @work_start_date = 17/08/06 ).
Conversion failed when converting datetime from character string.
No rows affected.
(0 row(s) returned)
@RETURN_VALUE =
Finished running [dbo].[dsp_update_works].
Sorry, I replied before getting your following 2 comments.
Further to your addtional comments, below is my amended SP. But it's still erroring?
ALTER PROCEDURE dbo.dsp_update_works
(
@work_id int,
@work_start_date varchar(30),
@work_start_time varchar (30)
)
AS
UPDATE dtb140_works
SET work_start =@work_start_date + ' ' + @work_start_time
WHERE (work_id = @work_id)
IF @@ERROR <> 0
BEGIN
RAISERROR ('Update Works failed.',18,1)
RETURN
END
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2006-04-06 at 10:07:28ID: 16393747
U dont need the conversion, because already these are varchar
@work_start_date varchar,
@work_start_time varchar