Error in conversion of ssis task flow

Hello experts

I am trying to execute a sql statement and taking it into a variable 'count', the count value could be any integer, now if i assigned 'string' as its data type, if i change it to int32, it fails. now following that i have 2 exec sql tasks.

From the result set above, if my count is 0, then i should update a table as failure, if not success.

Now the error i am getting is
"The data types "DT_WSTR" and "DT_I4" are incompatible for binary operator ">". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator", i tried to google it, but couldn't solve the problem.

Thanks
parpaaAsked:
Who is Participating?
 
Brendt HessSenior DBACommented:
Assuming the variable is the string value, I would:

WHERE Cast(@Count as Int) < 1 AND Cast(@Count As Int) > 0

.... but why a count between 0 and 1?  Just a poor example?


Alternately, create a second variable and CAST it into that, e.g.:

DECLARE @iCt int
SET @iCt = Cast(@Count as Int)
....
WHERE @iCt >0 AND @iCt < 1
0
 
Brendt HessSenior DBACommented:
The problem is in the basic logic of comparing a string to a number.  Is the number 144 (not the string '144', but the numeric value) greater than or less than 'Cat'?  It's undefined, so you must explicitly cast one of the values (probably the wstr value) to a compatible type for the comparison.
0
 
parpaaAuthor Commented:
ok yes i agree with that, but i dont know why for some reason if i only mention string as the data type it suceeds. here is my variable @count, now my current expression comparison is @count < 1  and @count >0, what would be the syntax to include the cast for one of them?
0
 
parpaaAuthor Commented:
i got it..

>>but why a count between 0 and 1?  Just a poor example?
 my count result would be any integer starting 0.f


thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.