我有兩個字段保存數據爲varchar轉換VARCHAR到十進制
字段1 = 10,000.00和Field2 = 5,000.00
我現在需要添加這兩個領域找到總和。但是,當我添加爲字段1 +字段2的
結果是10,000.005,000.oo
我試圖用CAST(字段1爲十進制(12,2)),但它拋出一個錯誤,它不能將varchar轉換爲數字。
幫我一把。
SELECT [1] AS ContractPriceExcluded, [2] AS Anticipated, [3] AS Approved, [4] AS claims, [5] AS ProvisionalSums, [6] AS CommitmentsToDate, [7] AS AnticipatedFCost,
[8] AS VarianceToContract, [9] AS CertifiedPayments,[10] AS ContractPriceIncluded , [11] AS ProvisionalSumsNotactivated ,description, status, ReferenceNo
FROM (SELECT ISNULL([Workflow_CustomFormfields].[fieldnumber], '') AS fieldnumber,
CAST(REPLACE([Workflow_CustomFormFields].fieldvalue,',','')as Decimal(12,2)) AS fieldvalue, isnull(workflow_customforms.subject, '') AS description,
isnull(workflow_customforms.categoryvalue, '') AS status, isnull(workflow_customforms.reference, '') AS ReferenceNo
FROM [dbo].[Workflow_CustomFormfields] INNER JOIN
dbo.Workflow_CustomForms ON [dbo].[Workflow_CustomForms].[Id] = dbo.Workflow_CustomFormfields.customformId
WHERE dbo.Workflow_CustomForms.ProjectId = 1 AND dbo.Workflow_CustomForms.CustomformtypeId = 75) PS PIVOT (max(fieldvalue) FOR fieldnumber IN ([1], [2],
[3], [4], [5], [6], [7], [8], [9],[10],[11])) AS pivot_fieldvalue
爲什麼不把它作爲小數保存在第一位呢? –