• Danasegarane.A (6/19/2008)


    I am not able to understand this one

    I run this query

    if 'BLONP' < Any (select customerid from customers)

    select '1'

    else

    select '0'

    But it returns 1 only ?

    What's your customer table - I assume that the customerid column is some kind of char-based column for the above not to return you a conversion failure.

    Try the following...

    CREATE TABLE [dbo].[TimeGroup](

    [column1] [nchar](10) COLLATE Latin1_General_CI_AS NULL

    ) ON [PRIMARY]

    Insert into the TimeGroup table values Value1, Value2, Value3, Value4

    run the query as posted in the question and it will return 1 for any value in the if statement less than 'Value4'. Value4 is the highest value in you've added to column1, so here it will return 0. If you change the operator to =, it will return 1 for Value4.

    i.e.

    if 'Value1' < any ( select column1 from TimeGROUP )

    select '1'

    else

    select '0'

    Returns 1

    if 'Value4' < any ( select column1 from TimeGROUP )

    select '1'

    else

    select '0'

    Returns 0

    if 'Value4' = any ( select column1 from TimeGROUP )

    select '1'

    else

    select '0'

    Returns 1

    and so on...:)