假设我有以下数据要在FOR XML EXPLICIT查询中使用:
ItemId: 14528097
ProductId: 7575
Revenue: 12.95
PerItemPrice: 12.95
Quantity: 1现在,当我编写我的查询时,我得到了以下输出:
<ItemId>14528097</ItemId>
<ProductId>7575</ProductId>
<Revenue>12.9500</Revenue>
<PerItemPrice>1.295000000000000e+001</PerItemPrice>
<Quantity>1.000000000000000e+000</Quantity>有没有办法让它看起来像这样:
<ItemId>14528097</ItemId>
<ProductId>7575</ProductId>
<Revenue>12.9500</Revenue>
<PerItemPrice>12.95</PerItemPrice>
<Quantity>1</Quantity>还是我不走运?
发布于 2011-08-01 22:59:15
看起来a1ex07比我先找到答案,但我怀疑您使用的是FLOAT或REAL (无论是有意还是无意),我建议对不明确需要FLOAT/REAL属性的数值始终使用DECIMAL。
发布于 2011-08-01 22:58:24
这个查询运行得很好,所以请确保您的类型转换正确:
declare @t table (
ItemId varchar(10),
ProductId varchar(5),
Revenue decimal(9,2),
PerItemPrice decimal(9,2),
Quantity int)
insert into @t select '14528097','7575',12.95,12.95,1
select 1 as 'Tag', NULL as 'Parent',
NULL as 'Items!1!',
NULL as 'Item!2!Item',
NULL as 'Item!2!Revenue'
union
select 2, 1, NULL, ItemId, Revenue
from @t for xml explicit发布于 2011-08-01 22:59:34
对比使用浮点列和十进制列的结果。
浮动..。
create table #testfloat (a float)
insert into #testfloat values (1)
select * from #testfloat for xml auto
drop table #testfloat
<a="1.000000000000000e+000"/>现在使用decimal类型...
create table #testdec (a decimal(5,2))
insert into #testdec values (1)
select * from #testdec for xml auto
drop table #testdec
<a="1.00"/>https://stackoverflow.com/questions/6900175
复制相似问题