I have a table where one of the columns has a sql_variant
datatype. I'm trying to modify the column to VarChar(800)
but I'm getting an error:
Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query
I tried using the Convert
statement in the Alter
statement but I'm getting an incorrect syntax error. I would really appreciate it if someone can shed some light on how this problem can be resolved. Thank you!
Script:
ALTER TABLE dbo.tmpEmployee
ALTER COLUMN bigVal Varchar(800)
bigVal
is the column of sql_variant
datatype.
This is the error:
Msg 257, Level 16, State 3, Line 5
Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.
I'm afraid this is not an easy task, if the order of column doesn't matter, just add a new column as varchar(800) and try to insert data from sql_varient to that column, but you have to be careful for different type of data in that column to use right casting format for example for dates and binary values
try this query
UPDATE dbo.tmpEmployee
SET bigVal = CONVERT(varchar(800),bigVal)
FROM tmpEmployee
ALTER TABLE dbo.tmpEmployee
ALTER COLUMN bigVal Varchar(800)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.