问题
I want insert all rows of a table into another table, and I also want convert a nvarchar
field into bigint
, but when I use convert(bigint, col1)
SQL Server shows an error:
Error converting data type nvarchar to bigint
How can I fix this problem?
回答1:
You could try to use ISNUMERIC
to determine those rows that are indeed numeric:
UPDATE dbo.YourTable
SET BigIntColumn = CAST(NVarcharColumn AS BIGINT)
WHERE ISNUMERIC(NVarcharColumn) = 1
That would convert those rows that can be converted - the others need to be dealt with manually.
回答2:
You should convert bigint to nvarchar not vice versa cast(Other_Column_name as nvarchar) not cast (Column_Name as bigint)
来源:https://stackoverflow.com/questions/5828510/convert-nvarchar-to-bigint-in-sql-server-2008