在SQL Server存储过程中将varchar转换为数字

时间:2017-07-31 12:41:48

标签: sql stored-procedures varchar user-defined-types sql-convert

我正在为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

这是确切的错误

  

Msg 102,Level 15,State 1,Procedure ImportEquipmentFile_UDT,Line 27
  ' Outcost'附近的语法不正确。

1 个答案:

答案 0 :(得分:5)

.row > .col-lg-10:hover + .col-lg-2 > .chatdate 中的列列表仅包含列名。值在insert

select