You must Sign In to post a response.
  • Category: SQL Server

    How to Convert a Table Column Float Datatype to Varchar in Sql Server 2008 R2

    Hi Developers

    In my sSql Database
    I have created one Student Marks table and inserted more than
    5000 student Marks with Float Data Type,
    Now i want to insert Text also. So how can i convert the Mark Column Float datatype to Varchar datatype.
    Please help me friends for i am done this task

    Thanking You
  • #767193

    If you want to ALTER your table structure then refer below Microsoft Syntax, this might be helpful to change your table column datatype.

    ALTER TABLE tablename
    ALTER COLUMN coulumnname VARCHAR(100)

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #767202
    Thanks Mr.Naveen Your Query is working exactly.


  • #767205
    Also you can use Str() function of SQL:

    DECLARE @num float = 1234567890;
    SELECT Str(@num, 20, 5);
    Insert into Table (FloatColumn) values (Str(@num, 20, 5))

  • #767211
    1. Create new column "FloatStudentMarks " of type Text
    2. Update the new column with "StudentMarks". "Str" method to convert.
    3. Now you can delete the old column(StudentMarks) and rename the "FloatStudentMarks " into "StudentMarks"

    I hope the above logic will help you changing the column type. You can also alter table. But there may a change possibility of loose of data. If you do the above logic. You may make sure by seeing the converted data and the remove the old column.

    By Nathan
    Direction is important than speed

  • #767218
    Just ALTER it using following syntax

    ALTER TABLE tablename ALTER COLUMN coulumnname datatype(size)
    //here you can use below syntax
    ALTER TABLE tablename ALTER COLUMN coulumnname VarChar(1000)

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • Sign In to post your comments