Question

I've got this dynamic t-sql:

declare @sql nvarchar(max)
set @sql =
N'
insert into #t
SELECT
    row_number() over(order by getdate()) as RowNum,
    d.value('''+@baseDateXpath+''', ''datetime'') as basedate,
    pref.query(''.'') as XmlExtract
FROM
    @content.nodes(''/*/*'') AS extract(pref)
CROSS APPLY
    @content.nodes(''//*'') AS datey(d)
WHERE
    pref.value(''.//*[1]'', ''nvarchar(50)'') IS NOT NULL'

exec sp_executesql @sql,
    N'@content xml',
    @anXmlContentStr

And it doesn't work because (I think) the escaping of the forward slashes is being mis-interpreted.

How do I write this string so that it will execute properly?

Was it helpful?

Solution

Could it just be that you have @content.nodes(''//'') AS datey(d) instead of @content.nodes(''//'') AS date(d)

If not what is the error that you are rec'ng?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top