x
login about faq Site discussion (meta-askssc)

Datatypes DT_WSTR and DT_Date are incompatable for binary operator + error in ssis expression

Hi,

am using an sql query in my expression where i need to fetch the data based on the date. For example this is the query am using in varibale. select * from employee where m_dtadddate = "+ @[System::StartTime] +"' AND m_eid='"+@[User::eid]+"'.
When i evaluate this expression it is showing error like Datatypes DT_WSTR and DT_Date are incompatable for binary operator + how to avoid this error

more ▼

asked May 25 '12 at 07:06 AM in Default

kumar537 gravatar image

kumar537
0 1 2 2

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Since it is the error at evaluation time, the root cause is that the Expression is of data type DT____WSTR, whereas the @[System::StartTime] is of data type DT___Date. To rectify this, you need to explicitly convert the data type of @[System::StartTime] to DT_WSTR. The simplest way could be

"select * from employee where m_dtadddate = '"+ (DT_WSTR, 25) @[System::StartTime] +"'..... 

But this could lead to date conversion issues. Based upon your source/destination, you may need to format the date string accordingly by using date-time functions etc..

Moreover, Thomas Rushton's suggestion is absolutely correct. You could be prompted a run time error (Not at the expression evaluation time) for the missing single quote. So please modify the expression as advised.

more ▼

answered May 28 '12 at 01:35 PM

Usman Butt gravatar image

Usman Butt
13.8k 6 8 14

(comments are locked)
10|1200 characters needed characters left

It looks to me as though you're missing a '

You have:

...WHERE m_dtadddate = " + @[System::StartTime]+ "' AND...

Shouldn't that be:

...WHERE m_dtadddate = '" + @[System::StartTime] + "' AND...

?

more ▼

answered May 25 '12 at 10:19 AM

ThomasRushton gravatar image

ThomasRushton ♦
30.1k 7 10 40

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.