在 SQL 服务器存储过程中将 varchar 转换为数字
Convert varchar into numeric in SQL Server stored procedure
我正在为 INSERT
编写一个存储过程,我想将 varchar
列转换为数字,所以当我编写这段代码时
CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT))
然后它抛出这个错误
Incorrect syntax near the keyword 'CONVERT'.
这是我的查询
INSERT INTO dbo.UdtEquipmentsStaging
([Type], [ModelID], [AccessoryID], [Make], [Model], [Category],
[CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum],
[Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5],
CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT)), [MSRP],
[Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor],
[ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes]
, [Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40])
SELECT
[Type], [ModelID], [AccessoryID], [Make], [Model], [Category],
[CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum],
[Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5],
[Outcost], [MSRP], [Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor],
[ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes],
[Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40]
FROM
@Equipments
这是准确的错误
Msg 102, Level 15, State 1, Procedure ImportEquipmentFile_UDT, Line 27
Incorrect syntax near 'Outcost'.
insert
中的列列表仅包含列名称。该值进入 select
:
INSERT INTO dbo.UdtEquipmentsStaging
( [Type], [ModelID], [AccessoryID], [Make], [Model], [Category], [CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum]
, [Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5], [Outcost], [MSRP], [Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor]
, [ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes]
, [Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40])
SELECT [Type], [ModelID], [AccessoryID], [Make], [Model], [Category], [CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum]
, [Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5], CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT)), [MSRP], [Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor]
, [ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes]
, [Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40]
FROM @Equipments
我正在为 INSERT
编写一个存储过程,我想将 varchar
列转换为数字,所以当我编写这段代码时
CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT))
然后它抛出这个错误
Incorrect syntax near the keyword 'CONVERT'.
这是我的查询
INSERT INTO dbo.UdtEquipmentsStaging
([Type], [ModelID], [AccessoryID], [Make], [Model], [Category],
[CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum],
[Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5],
CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT)), [MSRP],
[Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor],
[ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes]
, [Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40])
SELECT
[Type], [ModelID], [AccessoryID], [Make], [Model], [Category],
[CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum],
[Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5],
[Outcost], [MSRP], [Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor],
[ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes],
[Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40]
FROM
@Equipments
这是准确的错误
Msg 102, Level 15, State 1, Procedure ImportEquipmentFile_UDT, Line 27
Incorrect syntax near 'Outcost'.
insert
中的列列表仅包含列名称。该值进入 select
:
INSERT INTO dbo.UdtEquipmentsStaging
( [Type], [ModelID], [AccessoryID], [Make], [Model], [Category], [CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum]
, [Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5], [Outcost], [MSRP], [Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor]
, [ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes]
, [Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40])
SELECT [Type], [ModelID], [AccessoryID], [Make], [Model], [Category], [CategoryDescription], [Grouping], [Item], [RequiredModel], [SKU], [ProductNum]
, [Speed], [Description], [Cost], [Cost2], [Cost3], [Cost4], [Cost5], CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT)), [MSRP], [Discontinued], [PercentMSRP], [ServiceType], [ServiceTypeColor]
, [ConnectivityFee], [ConnectFee], [InstallFee], [Notes], [ManufactureNotes]
, [Special1], [Special2], [Special3], [Special4], [Special5], [Special6], [Special7], [Special8], [Special9], [Special10], [Special11], [Special12], [Special13]
, [Special14], [Special15], [Special16], [Special17], [Special18], [Special19], [Special20], [Special21], [Special22], [Special23], [Special24], [Special25]
, [Special26], [Special27], [Special28], [Special29], [Special30], [Special31], [Special32], [Special33], [Special34], [Special35], [Special36], [Special37]
, [Special38], [Special39], [Special40]
FROM @Equipments