Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 918
  • Last Modified:

SSIS: Conversion failed when converting date and/or time from character string

Hi All,

I have a problem.

I'm trying to insert a date value (which is a sting) into a date column (which is a date data type). The date is read from the file creation property of a file using the script task in C# as follows:

strFileDate = (FileObject.CreationTime.ToShortDateString)
        strFileTime = (FileObject.CreationTime.ToShortTimeString)

Open in new window


I pass the date and time to variables in SSIS and then from there I use the SQL task to try to insert the date and time variables into the SQL server table as follows:

INSERT INTO ag_opendatetime (OpenDate, OpenTime) SELECT '', ''

Open in new window


In the SQL task in Expressions I have set the following to read the values of the variables as follows:

"INSERT INTO ag_opendatetime (OpenDate, OpenTime) SELECT '"+ @[User::FileDate]+"', '"+@[User::FileTime] +"'"

Open in new window


Eventually I get the error
SSIS: Conversion failed when converting date and/or time from character string

I've tried every convert(date, cast( etc and it doesn't work. How can I make SQL server accept the string date and or time values?

Thanks,

Shaye
0
onesegun
Asked:
onesegun
1 Solution
 
Vikas GargBusiness Intelligence DeveloperCommented:
Hi,

In place of passing variable in the Execute SQL Task you can Write insert query like this

INSERT INTO [dbo].[CallData]
           ([insertProcess]
           ,[insertDTTM])
     VALUES
           (?,?)
And then Map the parameter it will work.

I tested this and there is no issue with it.
0
 
onesegunAuthor Commented:
Fantastic! That works. Thanks
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now