Sql 将Varchar转换为数值
我需要将导入的VarChar转换为文本,并找到了此代码Sql 将Varchar转换为数值,sql,sql-server,decimal,numeric,varchar,Sql,Sql Server,Decimal,Numeric,Varchar,我需要将导入的VarChar转换为文本,并找到了此代码 select * from [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] where ISNUMERIC(201307)=0 alter table [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] Add 201307_Temp decimal(17,4) GO --Update temporary column with the values f
select * from [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] where ISNUMERIC(201307)=0
alter table [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] Add 201307_Temp decimal(17,4)
GO
--Update temporary column with the values from 201307
update [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] set 201307_Temp = 201307
GO
--set 201307 to null
update [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] set 201307 = NULL
GO
--Change the datatype of 201307
alter table [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] alter column 201307 decimal(17,4)
GO
--Update the numeric values in 201307
--before doing this you have make sure select * from [VWSA_Sewells].[dbo]. [Sewells_1Mth_Composite] where ISNUMERIC(201307_Temp)=0 returns nothing.
update [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] set 201307 = Cast(201307_Temp as decimal(17,4))
GO
我的表格在标题201307下的第1列中包含一个比率ID,如VW1537 is02p和第2列中的实际比率
第201307列仅包含数字数据,如0.2242、5042050.40等。所有数字都不超过4位小数
SQL Server 2008中的错误消息为
Msg 102,15级,状态1,第3行
“201307”附近的语法不正确
只要decimal提供高达10亿的金额和4位数字,并允许查询>1等,我们就可以坚持使用decimal
有什么想法吗 这应该有效:
select * from [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] where ISNUMERIC([201307])=0
alter table [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] Add [201307_Temp] decimal(17,4)
GO
--Update temporary column with the values from 201307
update [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] set [201307_Temp] = [201307]
GO
--set 201307 to null
update [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] set [201307] = NULL
GO
--Change the datatype of 201307
alter table [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] alter column [201307] decimal(17,4)
GO
--Update the numeric values in 201307
--before doing this you have make sure select * from [VWSA_Sewells].[dbo]. [Sewells_1Mth_Composite] where ISNUMERIC(201307_Temp)=0 returns nothing.
update [VWSA_Sewells].[dbo].[Sewells_1Mth_Composite] set [201307] = Cast([201307_Temp] as decimal(17,4))
GO
Raj如果表和列名以数字开头,则必须在其周围使用方括号。那是你的错误。改变表格。。。添加[201307_Temp]decimal.。现在的问题是,表中的值被列标题替换了?这很可能是因为您没有将括号放在某个地方。可能在现场[201307_Temp]=[201307]我确实忘记了那个,会很快测试的!同样的问题-最终只是空扫描-你提供了一些样本数据吗?嗨,拉杰,我的结局是空的?