0

I am trying to assign concatenated string to my variable and I am getting the error "Error converting data type varchar to datetime."

Please Can you help me solve this problem.

declare @msg Varchar(max)
set @msg = 'select' + 'File Date: ' + CAST(GetDate() AS VARCHAR(Max))  + ' data imported successfully'


EXEC DataImport
@PackageName = '',
@Status= 'Successful', 
@Message = @msg,
@FileName = 'test',
@PackageExecutionDate = 'test',
@Step = 'Import Flat Files'
2
  • 1
    I removed the incompatible database tags. Your code does not make sense in either SQLite or MySQL. Commented Jul 27, 2020 at 14:05
  • There's no way a date string will grow beyond 4GB, so there's no reason to use varchar(max). If you want control over the date string you should either use CONVERT with a style or FORMAT with a format string. Commented Jul 29, 2020 at 10:32

2 Answers 2

1

You can use CONCAT(), which converts values automatically:

set @msg = concat('select', 'File Date: ', CAST(GetDate() AS VARCHAR(Max)), ' data imported successfully')

Neither of your original database tags support getdate() or varchar(max), so you probably have other problems as well.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @GordonLinoff, I have tried the CONCAT() it also did not work.
0

I have solved this problem by using C# code instead on converting directly on the SSIS Package using SQL. Thank you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.