cast Text datatype as int or varchar

  • I have to update a table based on a column from one table to the column of the other table.

    Table1(DetailId(int), ColumnName(varchar(50))

    Table2(Order_Comments(text), ColumnName(varchar(50))

    Update Table1

    Set ColumnName = t2.ColumnName

    FROM Table1 t1, Table2 t2

    WHERE t1.DetailId = CAST(t2.Order_Comments As int)

    I get an error when I do this - can't convert text to an int.

    I try casting both as varchar, but it doesn't work.

    Update Table1

    Set ColumnName = t2.ColumnName

    FROM Table1 t1, Table2 t2

    WHERE CAST(t1.DetailId As varchar(50)) = CAST(t2.Order_Comments As varchar(50))

    I can't change the datatype of Order_Comments in table2 since its done that way. The detailid is stored in table2 in the Order_Comments field.

  • This contains how u update data to a column with text data type

    http://msdn.microsoft.com/en-us/library/ms177523.aspx

    Look at examples 'G' & 'H' there.



    Pradeep Singh

  • Thanks PS. That helped.

  • bladerunner148 (6/15/2009)


    Thanks PS. That helped.

    You're welcome:-)



    Pradeep Singh

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply