0

我正在编写一个存储过程,INSERT并且我想将一varchar列转换为数字,所以当我编写这段代码时

CONVERT(NUMERIC(18,2), CAST([Outcost] AS FLOAT))

然后它抛出这个错误

关键字“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

这是确切的错误

消息 102,级别 15,状态 1,过程 ImportEquipmentFile_UDT,第 27 行
“Outcost”附近的语法不正确。

4

1 回答 1

5

中的列列表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
于 2017-07-31T12:44:36.743 回答