2013-02-01 34 views
5

इस में मूल्य मिल रहा है एक और 'एक्सएमएल के लिए' सवाल यह है, लेकिन मैं अनिश्चित इस स्पष्ट मोड बिना किया जा सकता है कि क्या कर रहा हूँ। यदि यह नहीं हो सकता है, तो मुझे बस इसके साथ रहना होगा।एसक्यूएल सर्वर 'एक्सएमएल के लिए' "पंक्ति" तत्व नोड

SELECT 
     [stream_id] as '@stream_id', 
     [path_locator] as '@path_locator', 
     [parent_path_locator] as '@parent_path_locatr', 
     [file_type] as '@file_type', 
     [cached_file_size] as '@cached_file_size', 
     [creation_time] as '@creation_time', 
     [last_write_time] as '@last_write_time', 
     [last_access_time] as '@last_access_time', 
     [is_directory] as '@is_directory', 
     [is_offline] as '@is_offline', 
     [is_hidden] as '@is_hidden', 
     [is_readonly] as '@is_readonly', 
     [is_archive] as '@is_archive', 
     [is_system] as '@is_system', 
     [is_temporary] as '@is_temporary', 
     [name] as '/name', 
     dbo.udf_GetChildren(path_locator) 
    FROM @Merged 
    WHERE path_locator.GetLevel() = 1 
    FOR XML PATH'file'), ROOT('files'), TYPE 

यह निम्न xml आउटपुट:

निम्नलिखित वर्तमान में मेरे बयान का चयन है

<files> 
    <file stream_id="" etc...> 
     <name>NAME</name> 
    </file> 
</files> 

यह बुरा नहीं है, लेकिन क्या मैं सच में करना चाहते हैं प्राप्त करने के लिए है नाम तत्व का मान फ़ाइल तत्व के मान के रूप में। यह इतना आसान काम है कि मुझे लगता है कि इसे स्पष्ट मोड के बिना किया जा सकता है, लेकिन मैं अक्सर ऐसी चीजों के बारे में गलत रहा हूं।

मैं '/' मार्कर का उपयोग करने की कोशिश की है, लेकिन इस आशय मैं (Update XML node (in an XML column) in SQL Server 2005 with another column value in the same row उदाहरण के लिए) चाहते हैं नहीं लगता है।

संपादित करें: वांछित एक्सएमएल बस इस होगा:

<files> 
    <file stream_id="" etc...>NAME</file> 
</files> 

मदद के लिए बहुत धन्यवाद।

+0

आप इच्छित XML आउटपुट का एक उदाहरण दिखा सकते हैं? –

+0

@AdamWenger किया। धन्यवाद। – dansan

+1

क्या आपने '*' नाम के रूप में नाम की कोशिश की है? –

उत्तर

3
+0

+1, सरल समाधान –

+0

@Adam एक बिल्ली को त्वचा के कई तरीके हैं। यहां सभी उत्तरों नौकरी करेंगे ताकि आप सभी को +1 कर सकें :) –

2

मुझे लगता है कि आप मैदान से दूर करने के लिए स्तंभ नाम है - क्या मैं अंत करने के लिए एक रिक्त स्थान concatonating के साथ ऐसा करने में सक्षम था।

SELECT name + '' 
FROM TestXML 
FOR XML PATH('file') 

और यहाँ SQL Fiddle है: यहाँ एक संक्षिप्त संस्करण है कि आप अपने ऊपर के उदाहरण के साथ काम करने के लिए सक्षम होना चाहिए।

और इसके बारे में एक अच्छा लेख:

http://msdn.microsoft.com/en-us/library/bb510469.aspx

यहाँ यह आपके ऊपर क्वेरी के साथ है:

SELECT 
    [stream_id] as '@stream_id', 
    [path_locator] as '@path_locator', 
    [parent_path_locator] as '@parent_path_locatr', 
    [file_type] as '@file_type', 
    [cached_file_size] as '@cached_file_size', 
    [creation_time] as '@creation_time', 
    [last_write_time] as '@last_write_time', 
    [last_access_time] as '@last_access_time', 
    [is_directory] as '@is_directory', 
    [is_offline] as '@is_offline', 
    [is_hidden] as '@is_hidden', 
    [is_readonly] as '@is_readonly', 
    [is_archive] as '@is_archive', 
    [is_system] as '@is_system', 
    [is_temporary] as '@is_temporary', 
    [name] + '', 
    dbo.udf_GetChildren(path_locator) 
FROM @Merged 
WHERE path_locator.GetLevel() = 1 
FOR XML PATH'file'), ROOT('files'), TYPE 

गुड लक।

1

मैं प्रत्येक कॉलम को file नोड ले जाया गया:

SELECT [stream_id] AS 'file/@stream_id' 
    , [is_system] AS 'file/@is_system' 
    , [is_temporary] AS 'file/@is_temporary' 
    ... 
    , [name] AS 'file' 
FROM Merged 
FOR XML PATH('files'), TYPE;