We help IT Professionals succeed at work.
Get Started

Convert string to date

93 Views
Last Modified: 2016-03-23
Hi,

I NEED HELP PLEASE! :-)

I have an excel sheet that has a data from a vendor.
One of the field that I need from the excel sheet is the Submit_Date.
they have it as string nvarchar "February 12, 2015 2:07:21 PM EST"
I have created a table with that field as datetime.

the problem that I'm having when I do my import from excel to SQL. it import the Submit_Date as string from excel
but my table " ClearQuestReport" has Submit_Date as datetime .
when I run my stored Procedure I get this error

ERROR:
Msg 241, Level 16, State 1, Procedure CQ_ClearQuestReport, Line 24
Conversion failed when converting date and/or time from character string.

This is my stored Procedure.

what I need is to convert Submit_Date field from string to datetime field when I import the data into my table "ClearQuestReport"

UPDATE ClearQuestReport
SET 
id = ClearQuestReport_Import.id,
Headline = ClearQuestReport_Import.Headline,
Description = ClearQuestReport_Import.Description,
Submited_By = ClearQuestReport_Import.[Submited By],
Submit_Date = ClearQuestReport_Import.Submit_Date
FROM ClearQuestReport
    INNER JOIN ClearQuestReport_Import ON ClearQuestReport.id = ClearQuestReport_Import.id

--This will insert all non matching records
INSERT INTO ClearQuestReport(id,Headline,Description,Submited_By,Submit_Date)
SELECT id,Headline,Description,[Submited By],Submit_Date
FROM ClearQuestReport_Import
WHERE 
NOT EXISTS (SELECT 1 
                 FROM ClearQuestReport
                 WHERE ClearQuestReport.Id = ClearQuestReport_Import.Id)


SELECT * FROM ClearQuestReport

Open in new window


Thank you
Comment
Watch Question
Software Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE