how to use convert for an alias name of column in case statement

  • Hi experts,

    In the below case statement, the Salespersonflag column is being returned. when i use this case statement in a select and use that statement in a SSIS package i see the output column datatype for salespersonflag is DT_14. I want the case statement to return a DT_BOOL which is a bit datatype. can any one help me?

    CASE

    WHEN sp.[SalesPersonID] IS NULL THEN cast(0 as bit)

    ELSE cast(1 as bit)

    END AS [SalesPersonFlag]

    I have tried the below options but did not work.

    1. use cast/convert to the entire case statement.

    2. using cast for 1 and 0 values that are being shown as above.

    But the end result shown is as DT_14 in my package metadata. Appreciate your inputs on how to get the case statement returning a bit value.

    Thanks

    Koti

  • Not sure but try this

    CAST(CASE

    WHEN sp.[SalesPersonID] IS NULL THEN 0

    ELSE 1

    END AS BIT)AS [SalesPersonFlag]

    --------------------------------------------------------------------------------------------------
    I am just an another naive wannabe DBA trying to learn SQL Server

  • 🙂 I have tired that option too but the same.

  • --edited, as a duped answer that does not work....

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply