在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, notvarchar
. See, for example:
http://technet.microsoft.com/en-us/magazine/dd424925.aspx[^].—SA