在SQL Server中将Varchar转换为Int Data类型 [英] Convert Varchar to Int Data type in sql server

查看:218
本文介绍了在SQL Server中将Varchar转换为Int Data类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello iam使用sqlserver 2008.

Iam将table1与studentid列作为int。另一个表table12与studentntid列为id.Now我必须将数据从table1移动到table2.Before我需要检查table1中的数据是否为整数。如果它是整数,我需要允许它到table2。



我试过isnumeric(studentid ),它接受浮动也像10.0

我试过转换(studentid,int),抛出错误:无法从varchar转换为int。





感谢您的帮助

Hello iam using sqlserver 2008.
Iam having table1 with studentid column as int.And another table table12 with same studentid column as id.Now i have to move the data from table1 to table2.Before dat i need to check whether the data in table1 is integer or not.If it is integer,i need to allow it to table2.

I have tried isnumeric(studentid),it is accepting float also like 10.0
I tried with convert(studentid,int),throwing error :cannot convert from varchar to int.


Thanks for any help

推荐答案

这个问题反映了这些日子初学者最大的谬误之一:工作趋势用字符串表示数据而不是数据本身。如果需要在某些列中包含整数值,请使用一些数字,整数数据类型,而不是 varchar 。例如,请参阅:

http://technet.microsoft.com/en -us / magazine / dd424925.aspx [ ^ ]。



-SA
This question reflects one of the biggest fallacies of the beginners these days: a trend to work with strings representing data instead of data itself. If you need to have integer values in some columns, use some numeric, integer data types, not varchar. See, for example:
http://technet.microsoft.com/en-us/magazine/dd424925.aspx[^].

—SA


这篇关于在SQL Server中将Varchar转换为Int Data类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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