is there any difference between != and <>

  • karthik M

    One Orange Chip

    Points: 29139

    Pls tell me

    karthik

  • Peter Gadsby

    SSCrazy

    Points: 2718

    I think they are the same

    Pete

    Peter Gadsby
    Business Intelligence Consultant
    www.hgconsult.co.uk

  • Mayank Khatri

    SSCertifiable

    Points: 7874

    A) <>

    B) !=

    Both mean NOT EQUAL TO but (B) is not SQL 92 standard (The third version of SQL Server)

  • Jeff Moden

    SSC Guru

    Points: 994680

    I agree with Mayank... just to add to that, the != will actually appear in execution plans as <>. Sounds strange, but I can always tell who wrote the code if != is used... some Java programmer 😉

    The reason I really don't like it is because 1) it's not what I'm accustomed to for identifying an inequality (used to <> because of Math) and 2) for some reason, it's hard for me to see when I'm reviewing code... I guess I just don't think there should be an = sign in an inequality 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Gail Shaw

    SSC Guru

    Points: 1004446

    Jeff Moden (11/7/2007)


    Sounds strange, but I can always tell who wrote the code if != is used... some Java programmer 😉

    😀 I always use !=, but I'm not a Java programmer. An old habit from my C background... 😉

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Jeff Moden

    SSC Guru

    Points: 994680

    Heh... I was going to include "C" programmers in that mix :D, but wasn't sure it was true and I work mostly with Java programmers to boot.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Shaun McGuile

    SSCarpal Tunnel

    Points: 4111

    != is th inequality in C# get used to it as CLR programming takes off!:hehe:

    Hiding under a desk from SSIS Implemenation Work :crazy:

  • Vincent Chute

    Newbie

    Points: 7

    Jeff Moden (11/7/2007)The reason I really don't like it is because 1) it's not what I'm accustomed to for identifying an inequality (used to <> because of Math) and 2) for some reason, it's hard for me to see when I'm reviewing code... I guess I just don't think there should be an = sign in an inequality 😉

    The exact opposite for me.

    I learnt != in maths so seeing <> has always been a wtf moment for me.

    Just different notation dialects.

    "!" being a shorthand for the logical NOT operator means != is almost instinctive for me.

    Similarly I use "~" as shorthand for approx* whenever I am writing notes for myself.

  • Jeff Moden

    SSC Guru

    Points: 994680

    Shaun McGuile (11/9/2007)


    != is th inequality in C# get used to it as CLR programming takes off!:hehe:

    Heh... good point. But have had this argument with many other folks... there's very little you will ever need a CLR for if you actually know T-SQL well 😉 CLR's are for "C" programmers that don't 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Jeff Moden

    SSC Guru

    Points: 994680

    Vincent Chute (11/9/2007)


    The exact opposite for me.

    I learnt != in maths so seeing <> has always been a wtf moment for me.

    Just different notation dialects.

    "!" being a shorthand for the logical NOT operator means != is almost instinctive for me.

    Similarly I use "~" as shorthand for approx* whenever I am writing notes for myself.

    Perfect answer... "Just different notation dialects"...

    Now, using the Tilde to represent approximation is something that I agree with!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Michael Valentine Jones

    SSC Guru

    Points: 64818

    These all give me the same query plan:

    select * from authors where au_id <> '172-32-1176'

    select * from authors where au_id != '172-32-1176'

    select * from authors where not au_id = '172-32-1176'

  • Jeff Moden

    SSC Guru

    Points: 994680

    Heh... also notice that the != gets converted to a <> in the query plan output 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Gail Shaw

    SSC Guru

    Points: 1004446

    Jeff Moden (11/9/2007)


    Heh... good point. But have had this argument with many other folks... there's very little you will ever need a CLR for if you actually know T-SQL well 😉 CLR's are for "C" programmers that don't 😛

    I'll disagree with you on that point. There's a lot of things that the CLR is better at than T-SQL. String manipulation, complex mathematical calculations, external calls (web service). All far easier and far faster from CLR functions/procs

    Whether or not those belong in the DB in the first place is a different argument. 🙂

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Jeff Moden

    SSC Guru

    Points: 994680

    Sting manipulation? Complex mathematical calcs? Heh... Let's have a race... let's start with string manipulation... How about splitting a comma seperated column and returning a table with the PK of each row and the split value... 1 row for every split on a 100k row table? You write a CLR to solve, I'll write the T-SQL to solve. I'll even be happy to provide the test data if you want.

    Or, how about doing Init Caps on a column in a million row table?

    Or, how about removing all characters except digits and letters from a column in a million row table?

    Or, name the problem...

    ...and here's your advantage... I don't have 2k5 to play with... I have to do it using only T-SQL 'cause I only have 2k. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Shaun McGuile

    SSCarpal Tunnel

    Points: 4111

    Jeff you rascal 😀

    Hiding under a desk from SSIS Implemenation Work :crazy:

Viewing 15 posts - 1 through 15 (of 63 total)

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