how we change one data type into another in sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veer
    New Member
    • Jul 2007
    • 198

    how we change one data type into another in sql

    hello expert
    can any one help me by providing the way how we can change a column data type from one into another
    e,g i have a column which have datatype numeric and i want to change it into Integer
    thanks in advance
  • Jim Doherty
    Recognized Expert Contributor
    • Aug 2007
    • 897

    #2
    Originally posted by veer
    hello expert
    can any one help me by providing the way how we can change a column data type from one into another
    e,g i have a column which have datatype numeric and i want to change it into Integer
    thanks in advance
    Look at the CAST and CONVERT functions and reference them in your SQL

    typically :

    SELECT CONVERT (int,YourNumeri cfieldname) as MyIntegerField FROM YourTableName

    Regards

    Jim :)

    Comment

    • veer
      New Member
      • Jul 2007
      • 198

      #3
      hello expert
      i am not understanding your query , is it right syntax
      SELECT CONVERT (int,entry) as record FROM output
      where entry is the numeric column name and record is the new column name
      please check it and correct
      thanks




      Originally posted by Jim Doherty
      Look at the CAST and CONVERT functions and reference them in your SQL

      typically :

      SELECT CONVERT (int,YourNumeri cfieldname) as MyIntegerField FROM YourTableName

      Regards

      Jim :)

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Originally posted by veer
        hello expert
        i am not understanding your query , is it right syntax
        SELECT CONVERT (int,entry) as record FROM output
        where entry is the numeric column name and record is the new column name
        please check it and correct
        thanks
        You can just try out and check if it works isint it?
        Post back if it throws any error

        Comment

        • veer
          New Member
          • Jul 2007
          • 198

          #5
          it shows the syntax error near "as " keyword
          and when i use another command
          "select convert(int, entry) from output"
          it execute but not conver the numeric data type to integer


          Originally posted by amitpatel66
          You can just try out and check if it works isint it?
          Post back if it throws any error

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Originally posted by veer
            it shows the syntax error near "as " keyword
            and when i use another command
            "select convert(int, entry) from output"
            it execute but not conver the numeric data type to integer
            Why dont you try this one:

            [code=sql]
            ALTER TABLE table1 MODIFY (entry INT);

            [/code]

            But before running above query, you need to empty the table and then run alter command. so take a backup of the data,run the above alter command and reload the data

            Comment

            • veer
              New Member
              • Jul 2007
              • 198

              #7
              shows the syntax error on modify
              is there any probleum with version of sql because i am using sql server 2000



              Originally posted by amitpatel66
              Why dont you try this one:

              [code=sql]
              ALTER TABLE table1 MODIFY (entry INT);

              [/code]

              But before running above query, you need to empty the table and then run alter command. so take a backup of the data,run the above alter command and reload the data

              Comment

              • amitpatel66
                Recognized Expert Top Contributor
                • Mar 2007
                • 2358

                #8
                Originally posted by veer
                shows the syntax error on modify
                is there any probleum with version of sql because i am using sql server 2000
                Tryh this:

                [code=sql]

                ALTER TABLE <table>
                { [ ALTER COLUMN <column_name>
                { <new_data_typ e> [ ( <precision> [ , <scale> ] ) ]

                [/code]

                Comment

                Working...