請參閱下面的示例代碼:更改別名生成的查詢
DECLARE @TEST TABLE (
NAME VARCHAR(100)
)
INSERT into @TEST VALUES ('NAME_1')
INSERT into @TEST VALUES ('NAME_2')
SELECT NAME AS '@NAME'
FROM @TEST
FOR XML PATH ('POSITION'), ROOT ('POSITIONS')
The result is:
<POSITIONS>
<POSITION NAME="NAME_1" />
<POSITION NAME="NAME_2" />
</POSITIONS>
I would like to condition the query to have something like this:
<POSITIONS>
<POSITION NAME_MAIN="NAME_1" />
<POSITION NAME_BACKUP="NAME_2" />
</POSITIONS>
是否可以調節基於查詢的值的XML屬性?
when NAME IS NAME_1 THEN NAME_MAIN
when NAME IS NAME_2 THEN NAME_BACKUP?
應根據病情 – John 2013-04-29 11:32:08
哎呀作爲選\ @NAME_MAIN或\ @NAME_BACKUP別名...我沒有注意到第二個值。對不起 – TechDo 2013-04-29 11:33:19