Error in conversion of ssis task flow

Posted on 2009-12-21
Last Modified: 2013-11-10
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.

Question by:parpaa
    LVL 32

    Expert Comment

    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.

    Author Comment

    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?
    LVL 32

    Accepted Solution

    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

    Author Comment

    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


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now