Home All Groups Group Topic Archive Search About

why is it giving output ?

Author
22 Dec 2005 6:34 AM
Manish Sukhija
Hi,
   when i run this query
               select * from personal where phone > '40-8496-7223'
                          it works fine, eventhough i declared phone as
varchar type, it should not operate on > operator.
                                      what could be reason

Author
22 Dec 2005 6:56 AM
Uri Dimant
Hi ,Manish

I think that SQL Server internally convert a first character to the INT and
compare them



IF '130-0074321'>'211-4988260'
PRINT 'Yes'
ELSE
PRINT 'No'


In above example SQL Server is comparinmg 1 (first character)  from the
first parameter to the 2 (first character)  from the second parameter  and
result is NO





Show quote
"Manish Sukhija" <ManishSukh***@discussions.microsoft.com> wrote in message
news:C4ABE18E-6C0D-4B91-9F7E-30454D398737@microsoft.com...
> Hi,
>   when i run this query
>               select * from personal where phone > '40-8496-7223'
>                          it works fine, eventhough i declared phone as
> varchar type, it should not operate on > operator.
>                                      what could be reason
Author
22 Dec 2005 10:20 AM
Roji. P. Thomas
Uri,

    There is no implicit conversion. The > operator works on the (ASCII ?)
value of the characters.

IF 'AAAC'>'AAAB'
PRINT 'Yes'
ELSE
PRINT 'No'

--
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com


Show quote
"Uri Dimant" <u***@iscar.co.il> wrote in message
news:eTjC9SsBGHA.916@TK2MSFTNGP10.phx.gbl...
> Hi ,Manish
>
> I think that SQL Server internally convert a first character to the INT
> and compare them
>
>
>
> IF '130-0074321'>'211-4988260'
> PRINT 'Yes'
> ELSE
> PRINT 'No'
>
>
> In above example SQL Server is comparinmg 1 (first character)  from the
> first parameter to the 2 (first character)  from the second parameter  and
> result is NO
>
>
>
>
>
> "Manish Sukhija" <ManishSukh***@discussions.microsoft.com> wrote in
> message news:C4ABE18E-6C0D-4B91-9F7E-30454D398737@microsoft.com...
>> Hi,
>>   when i run this query
>>               select * from personal where phone > '40-8496-7223'
>>                          it works fine, eventhough i declared phone as
>> varchar type, it should not operate on > operator.
>>                                      what could be reason
>
>
Author
22 Dec 2005 7:47 AM
Chris2
"Manish Sukhija" <ManishSukh***@discussions.microsoft.com> wrote in
message news:C4ABE18E-6C0D-4B91-9F7E-30454D398737@microsoft.com...
> Hi,
>    when i run this query
>                select * from personal where phone > '40-8496-7223'
>                           it works fine, eventhough i declared
phone as
> varchar type, it should not operate on > operator.
>                                       what could be reason

Manish Sukhija,

May I ask what makes you think that the > operator can't be used to
compare a varchar column to a string literal?


Sincerely,

Chris O.
Author
22 Dec 2005 1:44 PM
Raymond D'Anjou
"Manish Sukhija" <ManishSukh***@discussions.microsoft.com> wrote in message
news:C4ABE18E-6C0D-4B91-9F7E-30454D398737@microsoft.com...
> Hi,
>   when i run this query
>               select * from personal where phone > '40-8496-7223'
>                          it works fine, eventhough i declared phone as
> varchar type, it should not operate on > operator.
>                                      what could be reason

I'd just like to know WHY you would run such a query?
Author
22 Dec 2005 5:08 PM
Trey Walpole
sure it should.

how could you ORDER BY a [var]char column if one string couldn't be >
another?


Manish Sukhija wrote:
Show quote
> Hi,
>    when i run this query
>                select * from personal where phone > '40-8496-7223'
>                           it works fine, eventhough i declared phone as
> varchar type, it should not operate on > operator.
>                                       what could be reason

AddThis Social Bookmark Button