Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Can't Query with = ISNULL?

Can't Query with = ISNULL?

Scheduled Pinned Locked Moved Database
databasehelpquestion
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR Offline
    realJSOPR Offline
    realJSOP
    wrote on last edited by
    #1

    When I try to run this query, I get a message saying "Syntax error near '='" on the 2nd line (actually, any line that has the ISNULL check in it):

    SELECT o.ID
    ,o.[Name] = ISNULL([Name], 'NO VALUE')
    ,o.Abbreviation = ISNULL(Abbreviation, 'NO VALUE')
    ,o.OrgTypeID = ISNULL(OrgTypeID, 'NO VALUE')
    ,o.DisplayOrder = ISNULL(DisplayOrder, 999)
    ,s.MetricNumber
    ,s.Status = ISNULL(Status, 'U')
    ,s.Command
    FROM [dashboard].[tblSLOrganizations] o
    RIGHT OUTER JOIN [dashboard].[tblMetricStatus] s
    ON (s.Base = o.Abbreviation)
    ORDER BY DisplayOrder, MetricNumber

    If I comment out all of the "= ISNULL..." instances, the query works. What am I doing wrong?

    .45 ACP - because shooting twice is just silly
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

    S L 2 Replies Last reply
    0
    • realJSOPR realJSOP

      When I try to run this query, I get a message saying "Syntax error near '='" on the 2nd line (actually, any line that has the ISNULL check in it):

      SELECT o.ID
      ,o.[Name] = ISNULL([Name], 'NO VALUE')
      ,o.Abbreviation = ISNULL(Abbreviation, 'NO VALUE')
      ,o.OrgTypeID = ISNULL(OrgTypeID, 'NO VALUE')
      ,o.DisplayOrder = ISNULL(DisplayOrder, 999)
      ,s.MetricNumber
      ,s.Status = ISNULL(Status, 'U')
      ,s.Command
      FROM [dashboard].[tblSLOrganizations] o
      RIGHT OUTER JOIN [dashboard].[tblMetricStatus] s
      ON (s.Base = o.Abbreviation)
      ORDER BY DisplayOrder, MetricNumber

      If I comment out all of the "= ISNULL..." instances, the query works. What am I doing wrong?

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      S Offline
      S Offline
      Simon_Whale
      wrote on last edited by
      #2

      SELECT o.ID
      ,ISNULL(o.[Name], 'NO VALUE') AS Name
      ,ISNULL(o.Abbreviation, 'NO VALUE') AS abbreviation
      ,ISNULL(o.OrgTypeID, 'NO VALUE') AS OrgTypeID
      ,ISNULL(o.DisplayOrder, 999) AS DisplayOrder
      ,s.MetricNumber
      ,ISNULL(s.Status, 'U') AS Status
      ,s.Command
      FROM [dashboard].[tblSLOrganizations] o
      RIGHT OUTER JOIN [dashboard].[tblMetricStatus] s
      ON (s.Base = o.Abbreviation)
      ORDER BY DisplayOrder, MetricNumber

      L M 2 Replies Last reply
      0
      • realJSOPR realJSOP

        When I try to run this query, I get a message saying "Syntax error near '='" on the 2nd line (actually, any line that has the ISNULL check in it):

        SELECT o.ID
        ,o.[Name] = ISNULL([Name], 'NO VALUE')
        ,o.Abbreviation = ISNULL(Abbreviation, 'NO VALUE')
        ,o.OrgTypeID = ISNULL(OrgTypeID, 'NO VALUE')
        ,o.DisplayOrder = ISNULL(DisplayOrder, 999)
        ,s.MetricNumber
        ,s.Status = ISNULL(Status, 'U')
        ,s.Command
        FROM [dashboard].[tblSLOrganizations] o
        RIGHT OUTER JOIN [dashboard].[tblMetricStatus] s
        ON (s.Base = o.Abbreviation)
        ORDER BY DisplayOrder, MetricNumber

        If I comment out all of the "= ISNULL..." instances, the query works. What am I doing wrong?

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        after reading up a bit, I think you need an AS keyword:

        SELECT o.ID
        ,ISNULL(o.[Name], 'NO VALUE') as [Name]
        ...

        :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        C 1 Reply Last reply
        0
        • S Simon_Whale

          SELECT o.ID
          ,ISNULL(o.[Name], 'NO VALUE') AS Name
          ,ISNULL(o.Abbreviation, 'NO VALUE') AS abbreviation
          ,ISNULL(o.OrgTypeID, 'NO VALUE') AS OrgTypeID
          ,ISNULL(o.DisplayOrder, 999) AS DisplayOrder
          ,s.MetricNumber
          ,ISNULL(s.Status, 'U') AS Status
          ,s.Command
          FROM [dashboard].[tblSLOrganizations] o
          RIGHT OUTER JOIN [dashboard].[tblMetricStatus] s
          ON (s.Base = o.Abbreviation)
          ORDER BY DisplayOrder, MetricNumber

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          you beat me to it. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          S 1 Reply Last reply
          0
          • L Luc Pattyn

            you beat me to it. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Prolific encyclopedia fixture proof-reader browser patron addict?
            We all depend on the beast below.


            S Offline
            S Offline
            Simon_Whale
            wrote on last edited by
            #5

            Sorry :laugh: been doing queries like that most of the week

            1 Reply Last reply
            0
            • L Luc Pattyn

              after reading up a bit, I think you need an AS keyword:

              SELECT o.ID
              ,ISNULL(o.[Name], 'NO VALUE') as [Name]
              ...

              :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              C Offline
              C Offline
              Corporal Agarn
              wrote on last edited by
              #6

              If T-SQL it is not mandatory.

              1 Reply Last reply
              0
              • S Simon_Whale

                SELECT o.ID
                ,ISNULL(o.[Name], 'NO VALUE') AS Name
                ,ISNULL(o.Abbreviation, 'NO VALUE') AS abbreviation
                ,ISNULL(o.OrgTypeID, 'NO VALUE') AS OrgTypeID
                ,ISNULL(o.DisplayOrder, 999) AS DisplayOrder
                ,s.MetricNumber
                ,ISNULL(s.Status, 'U') AS Status
                ,s.Command
                FROM [dashboard].[tblSLOrganizations] o
                RIGHT OUTER JOIN [dashboard].[tblMetricStatus] s
                ON (s.Base = o.Abbreviation)
                ORDER BY DisplayOrder, MetricNumber

                M Offline
                M Offline
                Md Marufuzzaman
                wrote on last edited by
                #7

                Could you please clarify on why the column alias is required?

                Thanks Md. Marufuzzaman


                I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

                M 1 Reply Last reply
                0
                • M Md Marufuzzaman

                  Could you please clarify on why the column alias is required?

                  Thanks Md. Marufuzzaman


                  I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  While it is not required you end up with a result set with no relevant column headers and you cannot use such a query in a view.

                  Never underestimate the power of human stupidity RAH

                  M 1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    While it is not required you end up with a result set with no relevant column headers and you cannot use such a query in a view.

                    Never underestimate the power of human stupidity RAH

                    M Offline
                    M Offline
                    Md Marufuzzaman
                    wrote on last edited by
                    #9

                    Yep..I agreed Thanks.

                    Thanks Md. Marufuzzaman


                    I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups