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. I want help on Sql query

I want help on Sql query

Scheduled Pinned Locked Moved Database
databasehelpquestionannouncement
4 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.
  • P Offline
    P Offline
    Parameswar Mal
    wrote on last edited by
    #1

    Hi Friends I have a problems I have a table Employee two fields Name, Age Name Datatype is varchar() Age Datatype is Int() the table look likes this Name.........Age Ram.............23 Steve............22 when i swap this two fields using this query"update Employee set Age = Ename,Ename=Age;' then the error occured error is "Syntax error converting the varchar value 'Ram' to a column of data type int." If i changed the datatype of Age is "Int" to "Varchar" then the query runs. My question is if i don't changed the datatype then how i swap the two fields Plz help me....

    M D 2 Replies Last reply
    0
    • P Parameswar Mal

      Hi Friends I have a problems I have a table Employee two fields Name, Age Name Datatype is varchar() Age Datatype is Int() the table look likes this Name.........Age Ram.............23 Steve............22 when i swap this two fields using this query"update Employee set Age = Ename,Ename=Age;' then the error occured error is "Syntax error converting the varchar value 'Ram' to a column of data type int." If i changed the datatype of Age is "Int" to "Varchar" then the query runs. My question is if i don't changed the datatype then how i swap the two fields Plz help me....

      M Offline
      M Offline
      mr_lasseter
      wrote on last edited by
      #2

      It seems to me you don't understand the difference between a varchar column versus an int column. A varchar column is used to store text while an int column is used to store numbers. You cannot do what you are trying do, becuase you cannot put Text into an Integer column, which is why you get the error message 'Syntax error converting the varchar value 'Ram' to a column of data type int'. Further, I don't see any reason why you would ever want to do this, as it just doesn't make any sense.

      Mike Lasseter

      D 1 Reply Last reply
      0
      • M mr_lasseter

        It seems to me you don't understand the difference between a varchar column versus an int column. A varchar column is used to store text while an int column is used to store numbers. You cannot do what you are trying do, becuase you cannot put Text into an Integer column, which is why you get the error message 'Syntax error converting the varchar value 'Ram' to a column of data type int'. Further, I don't see any reason why you would ever want to do this, as it just doesn't make any sense.

        Mike Lasseter

        D Offline
        D Offline
        dotnetSong
        wrote on last edited by
        #3

        "cast age as varchar" convert data type for select caluse,dot know update

        1 Reply Last reply
        0
        • P Parameswar Mal

          Hi Friends I have a problems I have a table Employee two fields Name, Age Name Datatype is varchar() Age Datatype is Int() the table look likes this Name.........Age Ram.............23 Steve............22 when i swap this two fields using this query"update Employee set Age = Ename,Ename=Age;' then the error occured error is "Syntax error converting the varchar value 'Ram' to a column of data type int." If i changed the datatype of Age is "Int" to "Varchar" then the query runs. My question is if i don't changed the datatype then how i swap the two fields Plz help me....

          D Offline
          D Offline
          dotnetSong
          wrote on last edited by
          #4

          how about 'Cast age as varchar', not sure

          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