2011-12-28 90 views
0

我有一個存儲過程,我宣佈一個變量作爲輸出。在這個過程中,我需要有多個選擇語句。當他們不在同一個輸出中時,我沒有問題創建多個select語句,但是我找不到這個。如何在存儲過程的輸出中使用多個select語句?

經過部分程序讀取:SET @XmlOutput = (後,我想添加更多的選擇語句。

謝謝你的幫助!

ALTER PROC [dbo].[uspCreateGeoRssFile] 
AS 
    DECLARE @XmlOutput xml 
    SET @XmlOutput = (
     SELECT  
     CustomerName AS Title, esn, longitude, latitude, Device_Alias AS Description 
     FROM   
     LS_Variable_Listing AS item 
     WHERE  
     (triggers <> N'No Event Recorded') 
     AND (CustomerName = N'Hiland Partners, LLC') 
     ORDER BY timestamp_utc DESC 
     FOR XML AUTO, ROOT('channel'), ELEMENTS) 

    SELECT @XmlOutput 

回答

1

不知道你要在這裏做什麼,但你可以附加一個XML結果到另一個:

declare @x xml; 
declare @some_more_xml xml; 

.... 

set @x = (select @x, @some_more_xml for xml path(''), type); 

這也可能是內聯:

set @x = (
    select 
    (select 1 as foo for xml raw, root('root1'), type), 
    (select 2 as bar for xml raw, root('root2'), type) 
    for xml path(''), type 
); 

如果你想在現有的xml中添加元素,那麼最簡單的方法就是直到最後纔會引入root子句:

set @x = (
    select 
    (select ... for xml auto, type), 
    (select ... for xml auto, type) 
    for xml path(''), root('channel'), type 
); 
+0

我需要在xml文件中添加更多的元素,它們與上面的「item」元素處於同一級別。這些只是不會改變的靜態元素。我很抱歉,因爲沒有更多。 – John 2011-12-28 16:37:21

+0

@John請參閱編輯。 – GSerg 2011-12-28 16:45:09

+0

謝謝!它現在有效! – John 2011-12-28 22:15:03

相關問題