从varchar(32)结果中删除小数位

时间:2018-11-11 18:41:50

标签: varchar sqlcommand

我正在使用SQL和Windows批处理脚本从我们的POS下载库存,然后将其上传到第三方平台。该文件已成功下载和上传,但是第三方平台在格式化方面相当挑剔。具体来说,标题为“数量”的列将不接受小数位。

我已经搜索并尝试了各种不同的方法,但是似乎找不到可行的方法。该sql的棘手方面是,我必须使用联接才能创建标题行,并且我使用的格式为varchar(32),我在下面发布了sql,有什么建议吗?

set nocount ON

SELECT CAST('sku' as VARCHAR(32)) AS sku, 
CAST('quantity' as VARCHAR(32)) AS quantity
UNION
SELECT CAST(IM_BARCOD.BARCOD AS 
VARCHAR(32)) as sku, case when 
IM_INV.QTY_AVAIL > 0 then 
CAST(IM_INV.QTY_AVAIL AS VARCHAR(32)) else 
CAST(0 as VARCHAR(32)) END as quantity
FROM IM_BARCOD INNER JOIN IM_INV ON 
IM_INV.ITEM_NO = IM_BARCOD.ITEM_NO INNER 
JOIN IM_PRC ON IM_INV.ITEM_NO = 
IM_PRC.ITEM_NO INNER JOIN 
IM_ITEM ON IM_INV.ITEM_NO = IM_ITEM.ITEM_NO
UNION
SELECT CAST(IM_BARCOD.BARCOD AS 
VARCHAR(32)) as sku, case when 
IM_INV_CELL.QTY_AVAIL > 0 then 
CAST(IM_INV_CELL.QTY_AVAIL AS VARCHAR(32)) 
else CAST (0 as VARCHAR (32)) END as 
quantity FROM IM_BARCOD INNER JOIN IM_PRC 
ON IM_BARCOD.ITEM_NO = IM_PRC.ITEM_NO INNER 
JOIN IM_INV_CELL ON IM_BARCOD.ITEM_NO = 
IM_INV_CELL.ITEM_NO AND 
IM_INV_CELL.DIM_1_UPR=IM_BARCOD.DIM_1_UPR 
AND IM_INV_CELL.DIM_2_UPR = 
IM_BARCOD.DIM_2_UPR AND 
IM_INV_CELL.DIM_3_UPR =IM_BARCOD.DIM_3_UPR 
INNER JOIN 
IM_ITEM ON IM_BARCOD.ITEM_NO = 
IM_ITEM.ITEM_NO

0 个答案:

没有答案