sql datatype convertion error??

  • Aha.. right. What I meant was...

    select * from InitialData where [entry]='1'

    works for me...

  • prathibha_aviator (4/18/2013)


    Seraj Alam-256815 (4/18/2013)


    Yes, only else part will execute as the condition is not true. What is confusion? do you think 0=1 is correct?

    My requirement is to

    -Get the value stored in the InitialData.entry column where the Dept is ‘Support’, the entry_name is ‘Reporting’ and the OrgID is equal to 1234.

    oThe value of InitialData.entry can be ‘1’, ‘0’, NULL or record not present in my actual table.

    oIf the value of InitialData.entry is not equal to ‘1’ then assume ‘0’

    Well the description above does not match what you originally posted above (shown below).

    prathibha_aviator (4/18/2013)


    Table with Values

    CREATE TABLE InitialData

    (

    recno int PRIMARY KEY,

    Dept Varchar(30),

    entry_name Varchar(50),

    entry varchar(500),

    orgID int

    )

    INSERT INTO InitialData Values

    (1, 'Marketing', 'Timesservedstartdate', '8/6/2012 12:00:00 AM', 1234),

    (2, 'Sales', 'Timesservedstartdate', '8/6/2012 12:00:00 AM', 1234),

    (3, 'Development', 'Reporting', 'Somevalue', 1234),

    (4, 'HumanResources', 'Reporting', '1', 1234),

    (5, 'Support', 'Reporting', '1', 1234);

    Trying to test the condition that i developed...i want to compare all the rows with the entry value '1'. Any values other than 1 should be equal to 0 is the condition. NOTE: entry is a varchar column

    IF (SELECT COALESCE((SELECT dI.[entry] FROM dbo.InitialData AS dI WITH(NOLOCK) WHERE dI.Dept = 'Reporting'

    AND dI.entry_name = 'PledgeRequireBatch'

    AND dI.orgID = 1234

    AND dI.[entry] <> 1), 0)) = 1

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    I am getting the else statement result always but that is not what i want

    1MarketingTimesservedstartdate8/6/2012 12:00:00 AM1234

  • I know right but apply the same on below

    IF (SELECT COALESCE((SELECT dI.[entry] FROM InitialData AS dI WITH(NOLOCK) WHERE dI.dept= 'Support'

    AND dI.entry_name = 'Reporting'

    AND orgID = 1234) , 0)) = '1'

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    --Pra:-):-)--------------------------------------------------------------------------------

  • prathibha_aviator (4/18/2013)


    I know right but apply the same on below

    IF (SELECT COALESCE((SELECT dI.[entry] FROM InitialData AS dI WITH(NOLOCK) WHERE dI.dept= 'Support'

    AND dI.entry_name = 'Reporting'

    AND orgID = 1234) , 0)) = '1'

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    You mean...

    IF (SELECT COALESCE((SELECT dI.[entry] FROM InitialData AS dI WITH(NOLOCK) WHERE dI.dept= 'Support'

    AND dI.entry_name = 'Reporting'

    AND orgID = 1234

    AND dI.[Entry]='1') , 0)) = 1

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    but again.. it will evaluate to true and your select statement will bring back every record so what does it gain you?

  • Erin Ramsay (4/18/2013)


    prathibha_aviator (4/18/2013)


    I know right but apply the same on below

    IF (SELECT COALESCE((SELECT dI.[entry] FROM InitialData AS dI WITH(NOLOCK) WHERE dI.dept= 'Support'

    AND dI.entry_name = 'Reporting'

    AND orgID = 1234) , 0)) = '1'

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    You mean...

    IF (SELECT COALESCE((SELECT dI.[entry] FROM InitialData AS dI WITH(NOLOCK) WHERE dI.dept= 'Support'

    AND dI.entry_name = 'Reporting'

    AND orgID = 1234

    AND dI.[Entry]='1') , 0)) = 1

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    but again.. it will evaluate to true and your select statement will bring back every record so what does it gain you?

    Thankyou so so much Erin

    I just wanted that to work dats it....Now that i made it euqal to zero like below, I know that its working

    IF (SELECT COALESCE((SELECT dI.[entry] FROM InitialData AS dI WITH(NOLOCK) WHERE dI.dept= 'Support'

    AND dI.entry_name = 'Reporting'

    AND orgID = 1234

    AND dI.[Entry]='1') , 0)) = 0

    BEGIN

    Select * from InitialData

    END

    ELSE

    Select TOP 1 * FROM InitialData

    U walked me through out the example...I aprreciate it

    --Pra:-):-)--------------------------------------------------------------------------------

  • Glad to be able to help.

Viewing 6 posts - 16 through 20 (of 20 total)

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