0

我有一个表,其中包含一个数据类型为文本的包大小列,出于数学原因,我需要将其转换为整数。此列中的值通常看起来像“100ML”、“20GM”、“UD 20”、“13OZ”,这很棘手,偶尔会有像“6X12ML”、“UD 5X6ML”这样的值。其中带有“X”的那些我需要删除我目前正在使用的“ML”

Replace([TABLE_NAME].[COLUMN_NAME],"ML","")

在查询的表达式列中。我可以使用嵌套的替换函数来删除“ML”、“GM”、“OZ”和“UD”。我所有的尝试都失败了,我认为最终的解决方案是这样的

IIf([TABLE_NAME].[COLUMN_NAME] Like "X", (CInt(Left([TABLE_NAME].[COLUMN_NAME],InStr(1,[TABLE_NAME].[COLUMN_NAME],"X")-1))*CInt(Right([TABLE_NAME].[COLUMN_NAME],InStr(1,[TABLE_NAME].[COLUMN_NAME],"X")+1))),[TABLE_NAME].[COLUMN_NAME])

我尝试使用上面代码的变体但无济于事。感谢所有建议,我更愿意在一个查询中将其淘汰,但我确实意识到我可以使用 and 表达式,只需将“X”之前和之后的文本拆分为两个不同的表达式列。然后使用另一个查询来乘以这些值。

4

1 回答 1

1
QTY_ORDERED: IIf(InStr(1,Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ",""),"X")>1,[CRX_HISTORIC_PO].[QUANTITY]/Left(Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ",""),InStr(1,Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ",""),"X")-1)*Right(Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ",""),Len(Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ",""))-InStr(1,Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ",""),"X"))*-1,[CRX_HISTORIC_PO].[QUANTITY]/Replace(Replace(Replace(Replace([STANDARD_PRICING].[PACKAGE_AMOUNT],"GM",""),"ML",""),"UD","")," ","")*-1)

上面的代码是我用来完成手头任务的。

于 2013-10-11T18:00:18.307 回答