views:

37

answers:

1

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?

A: 

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?

TooFat
I'm going to mark this answer as correct, because I have to mark something, but no, I don't think that's what it was. It just started working, indisputably, a little later - so it could have been data - but I've removed the entire thing and redesigned the structure, which is better than doing dynamic SQL, of course.
Matt W
@Matt W: Please don't feel that you have to mark something. If this answer doesn't answer your question, then it doesn't help anyone for you to mark it as the answer.
Michael Myers