在插入语句中使用强制转换 [英] Using cast in insert statement

查看:43
本文介绍了在插入语句中使用强制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些原始数据从 Excel 插入到 MS SQL 2005 中的表中.其中一些数据格式不正确,即数量列被格式化为数字 12345 而我需要像 123.45 所以我使用这个CAST(TRANSACTION_HISTORY.AMOUNT 十进制)/100正确转换它.但是有没有办法在插入语句中使用强制转换??

I am inserting some raw data into a table in MS SQL 2005 from excel. Some of these data are not formatted correctly ie the amount colum is formatteT as a number 12345 whereas i need to be like 123.45 so i use this CAST(TRANSACTION_HISTORY.AMOUNT AS decimal) / 100 to convert it correctly. However is there a way to use the cast in an insert statement??

谢谢

推荐答案

您可以在使用数据的任何类型的语句(插入、更新、删除、选择)中使用 CAST.

You can use CAST in any kind of statement(Insert, update, delete, select) where you use data.

Insert into table1 values( CAST(col1 as nvarchar(50)) )

这篇关于在插入语句中使用强制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆