RE: xml nodes and user defined function
- From: Galex Yen [MSFT] <galexy@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Feb 2008 14:33:01 -0800
Please try the following:
create table test(id int identity(1,1), doc varchar(max))
create view dbo.[doc]
as
select id,
col.value('(./last_name)[1]','varchar(200)') as [Last Name],
col.value('(./first_name)[1]','varchar(200)') as [First Name]
from (select id, convert(xml, doc) as doc from test) u
cross apply doc.nodes('people/person') as t(col)
Regards,
Galex Yen
"ycgq@xxxxxxxxx" wrote:
Here is the script:.
create table test(id int identity(1,1), doc varchar(max))
create view dbo.[doc]
as
select id,
col.value('(./last_name)[1]','varchar(200)') as [Last Name],
col.value('(./first_name)[1]','varchar(200)') as [First Name]
from [test] u
cross apply (cast (doc as xml)).nodes('people/person') as t(col)
Doc is in xml format. There is error:Incorrect syntax near the keyword
'as'.
So I changed to use UDF.
create function dbo.toXML(@input nvarchar(max))
returns XML
as
begin
declare @xml_data xml
set @xml_data = cast(@input as xml)
return @xml_data
end
create view dbo.[doc]
as
select id,
col.value('(./last_name)[1]','varchar(200)') as [Last Name],
col.value('(./first_name)[1]','varchar(200)') as [First Name]
from [test] u
cross apply (toXML(doc)).nodes('people/person') as t(col)
But it still complains about "Incorrect syntax near ')'". Anyone can
help? Thanks a lot!
- References:
- xml nodes and user defined function
- From: ycgq
- xml nodes and user defined function
- Prev by Date: RE: Extract Attribute across many XML docs
- Next by Date: configuring Report Server
- Previous by thread: xml nodes and user defined function
- Next by thread: querying an XML string in SQL Server
- Index(es):
Relevant Pages
|