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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL 2008 Query Help

SQL 2008 Query Help

Scheduled Pinned Locked Moved Database
databasehelpquestion
9 Posts 3 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.
  • H Offline
    H Offline
    Hulicat
    wrote on last edited by
    #1

    Why would this simple select error like this: sql 2008? SELECT field1 FROM ADDRESS where field1 != 'NULL' "Error Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to numeric." The real goal is to get this select to work but there are two fields causing me problems. The two fields commented out are generating the same error as above....how would I insert a cast into the below query for fields 4 and 5? use dbname Select field1 + ' ' + ISNULL(field2,'') + ' ' + ISNULL(field3,'') --+ ' ' + ISNULL(field4,'') --+ ' ' + ISNULL(field5,'') as column_new from table1 Error converting data type varchar to numeric."

    Regards, Hulicat

    _ 1 Reply Last reply
    0
    • H Hulicat

      Why would this simple select error like this: sql 2008? SELECT field1 FROM ADDRESS where field1 != 'NULL' "Error Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to numeric." The real goal is to get this select to work but there are two fields causing me problems. The two fields commented out are generating the same error as above....how would I insert a cast into the below query for fields 4 and 5? use dbname Select field1 + ' ' + ISNULL(field2,'') + ' ' + ISNULL(field3,'') --+ ' ' + ISNULL(field4,'') --+ ' ' + ISNULL(field5,'') as column_new from table1 Error converting data type varchar to numeric."

      Regards, Hulicat

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      Hulicat wrote:

      SELECT field1 FROM ADDRESS where field1 != 'NULL'

      select field1 from ADDRESS where field1 is not null

      Hulicat wrote:

      how would I insert a cast into the below query for fields 4 and 5?

      select cast(field5 as varchar)

      I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

      H 1 Reply Last reply
      0
      • _ _Damian S_

        Hulicat wrote:

        SELECT field1 FROM ADDRESS where field1 != 'NULL'

        select field1 from ADDRESS where field1 is not null

        Hulicat wrote:

        how would I insert a cast into the below query for fields 4 and 5?

        select cast(field5 as varchar)

        I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

        H Offline
        H Offline
        Hulicat
        wrote on last edited by
        #3

        Thanks for the reply. I am having an issue inserting the cast into this statement for feilds 4, 5: use dbname Select field1 + ' ' + ISNULL(field2,'') + ' ' + ISNULL(field3,'') --+ ' ' + ISNULL(field4,'') --+ ' ' + ISNULL(field5,'') as column_new from table1

        Regards, Hulicat

        _ M 2 Replies Last reply
        0
        • H Hulicat

          Thanks for the reply. I am having an issue inserting the cast into this statement for feilds 4, 5: use dbname Select field1 + ' ' + ISNULL(field2,'') + ' ' + ISNULL(field3,'') --+ ' ' + ISNULL(field4,'') --+ ' ' + ISNULL(field5,'') as column_new from table1

          Regards, Hulicat

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #4

          Hulicat wrote:

          I am having an issue inserting the cast into this statement for feilds 4, 5:

          I already gave you that answer... Here it is in total since you seem to have not understood what I was talking about... use dbname Select field1 + ' ' + ISNULL(field2,'') + ' ' + ISNULL(field3,'') + ' ' + cast(field4 as varchar) + ' ' + cast(field5 as varchar) as column_new from table1

          I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

          1 Reply Last reply
          0
          • H Hulicat

            Thanks for the reply. I am having an issue inserting the cast into this statement for feilds 4, 5: use dbname Select field1 + ' ' + ISNULL(field2,'') + ' ' + ISNULL(field3,'') --+ ' ' + ISNULL(field4,'') --+ ' ' + ISNULL(field5,'') as column_new from table1

            Regards, Hulicat

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

            When you use the cast as per damians suggestion you need to define the size of the varchar as int ISNULL(Cast Field4 as varchar(20)),'')

            H _ 2 Replies Last reply
            0
            • M Mycroft Holmes

              When you use the cast as per damians suggestion you need to define the size of the varchar as int ISNULL(Cast Field4 as varchar(20)),'')

              H Offline
              H Offline
              Hulicat
              wrote on last edited by
              #6

              Thanks that was jamming me up....got it thanks.

              Regards, Hulicat

              1 Reply Last reply
              0
              • M Mycroft Holmes

                When you use the cast as per damians suggestion you need to define the size of the varchar as int ISNULL(Cast Field4 as varchar(20)),'')

                _ Offline
                _ Offline
                _Damian S_
                wrote on last edited by
                #7

                Mycroft Holmes wrote:

                you need to define the size of the varchar as int

                Interesting... not in SQL-2005 you don't!!

                I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

                M 1 Reply Last reply
                0
                • _ _Damian S_

                  Mycroft Holmes wrote:

                  you need to define the size of the varchar as int

                  Interesting... not in SQL-2005 you don't!!

                  I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

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

                  I am using 2008 and checked BOL before posting, I use Convert almost exclusively so I had to check, maybe the doco is out of date?

                  _ 1 Reply Last reply
                  0
                  • M Mycroft Holmes

                    I am using 2008 and checked BOL before posting, I use Convert almost exclusively so I had to check, maybe the doco is out of date?

                    _ Offline
                    _ Offline
                    _Damian S_
                    wrote on last edited by
                    #9

                    Maybe... I did it with SQL2005 before posting... don't have SQL2008 here...

                    I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

                    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