I have followed the above solution, but still i could not able to achieve it..
Here is my XML
<result>
<count>2</count>
<rows>
<row>
<f>
<n>id</n>
<v>8557526</v>
</f>
<f>
<n>vdb_id</n>
<v>16239</v>
</f>
<f>
<n>created</n>
<v>2014-12-10T08:50:18</v>
</f>
<f>
<n>task_id</n>
<v>5755155</v>
</f>
<f>
<n>process_id</n>
<v />
</f>
<f>
<n>update_comments</n>
<v />
</f>
</row>
<row>
<f>
<n>id</n>
<v>8567425</v>
</f>
<f>
<n>vdb_id</n>
<v>16239</v>
</f>
<f>
<n>created</n>
<v>2014-12-11T00:23:59</v>
</f>
<f>
<n>task_id</n>
<v>5755155</v>
</f>
<f>
<n>process_id</n>
<v />
</f>
<f>
<n>update_comments</n>
<v />
</f>
</row>
query :
USE tempdb
GO
IF OBJECT_ID('tempdb..#xml') IS NOT NULL DROP TABLE #xml
CREATE TABLE #xml ( yourXML XML )
GO
DECLARE @URL VARCHAR(8000)
DECLARE @QS varchar(50)
SELECT @QS = '&date='+convert(varchar(25),getdate(),126)
SELECT @URL = 'https://app.is.com/psa/api.do?function=query&table=db_time_entry& project_id=227666&token=c9adf' + @QS
DECLARE @Response varchar(8000)
DECLARE @XML xml
DECLARE @Obj int
DECLARE @Result int
DECLARE @HTTPStatus int
DECLARE @ErrorMsg varchar(MAX)
EXEC @Result = sp_OACreate 'MSXML2.ServerXMLHTTP.6.0', @Obj OUT
EXEC @Result = sp_OAMethod @Obj, 'open', NULL, 'GET', @URL, false
EXEC @Result = sp_OAMethod @Obj, 'setRequestHeader', NULL, 'Content-Type', 'application/x-www-form-urlencoded'
EXEC @Result = sp_OAMethod @Obj, send, NULL, ''
EXEC @Result = sp_OAGetProperty @Obj, 'status', @HTTPStatus OUT
INSERT #xml ( yourXML )
EXEC @Result = sp_OAGetProperty @Obj, 'responseXML.xml'--, @Response OUT
--SELECT yourXML.value('//result[1]//count[1]//rows[1]//row[1]//f[1]//n[1]//v[1] /id','VARCHAR(MAX)') from #xml
DECLARE @xml_value xml
select * from #xml
select @xml_value = yourXML from #xml
I tried this one
SELECT
Key1 = Item.value('(n)[1]', 'int'),
Key2 = Item2.value('(n)[1]', 'int'),
ItemValue = Item2.value('(v)[1]', 'varchar(50)')
FROM
@xml_value.nodes('/result/rows') AS T(Item)
CROSS APPLY
item.nodes('row/f') AS T2(Item2)
i got the out put like this
Key2 ItemValue
id 8557526
vdb_id 16239
created 2014-12-10T08:50:18
task_id 5755155
process_id
update_comments
id 8567425
vdb_id 16239
created 2014-12-11T00:23:59
task_id 5755155
process_id
update_comments
I need Output Like
ID vdb_id created task_id process_id update_comments
8557526 16239 2014-12-10 5755155 null null
please anyone tell me how I could select values from the XML and get the desired output Thanks in advance
Regards
T.Navin
