我正在为客户编写导出,并且他们要求所有字段都指向0到10位数。我在除了两个字段之外的所有字段上都这样做了。我正在使用此查询:
SELECT RIGHT('0000000000'+ISNULL(RTRIM(a.tqtyshp),''),10)as tqtyshp, RIGHT('0000000000'+ISNULL(RTRIM(a.price),''),11) AS price,
FROM artran a
LEFT JOIN arcust b ON a.custno = b.custno
WHERE invdte BETWEEN DATEADD("d",-7,GETDATE()) and GETDATE()+5 AND code = '127'
我得到以下结果:
003.000000 00034.64000
003.000000 00029.96000
003.000000 00032.65000
003.000000 00031.58000
003.000000 00022.18000
我需要将结果看起来像这样:
00000003.00 00000034.64
00000003.00 00000029.96
00000003.00 00000032.65
00000003.00 00000031.58
00000003.00 00000022.18
有问题的字段格式为十进制(15,6)
这与我昨天提出的问题相似,但在这个问题中我试图格式化小数位。另一个问题我只想让总字符数达到10个。
答案 0 :(得分:0)
怎么样
SELECT
RIGHT('0000000000' + cast(a.tqtysh AS varchar), 10) as tqtyshp,
RIGHT('0000000000'+ISNULL(CAST(a.price AS varchar),''),11) AS price,
FROM
artran a
LEFT JOIN arcust b ON a.custno = b.custno
WHERE
invdte BETWEEN DATEADD("d",-7,GETDATE()) and GETDATE()+5
AND code = '127'