SQLTeam.com | Weblogs | Forums

The argument 1 of the XML data type method "value" must be a string literal


I have a Problem.
I have an XMl Document with same named tags. So built i while to go by all elements. But when I want to try this

SELECT '''+cast(@FKDataSourceId as nvarchar)+''' as DataSoruceID, Z.Valuetype+''_''+Z.Accountcode as ID, Z.DateCreate, Z.DateValue, Z.Value INTO #Ifc_TempDataXML_EasyRent FROM(            
            ref.value(''dateto[1]'',''date'') AS DateValue,
            ref.value(''er_account[1]/accountid[1]'', ''NVARCHAR (255)'') AS Accountcode, 
            ref.value(''er_account[''+@xmlTag+'']/total_incltax[1]'', ''NVARCHAR (255)'') AS Value, 
            ref.value(''er_cashdeskid[1]'', ''NVARCHAR (255)'') AS Valuetype, 
            ref.value(''er_cashdeskid[1]'', ''NVARCHAR (255)'') AS Valuetext, 
            ref.value(''created_at[1]'', ''date'') AS DateCreate, 
            ref.value(''er_cashdeskid[1]'', ''NVARCHAR (255)'') AS Accountname, 
            ref.value(''er_cashdeskid[1]'', ''NVARCHAR (255)'') AS Mandator,
            ref.value(''er_cashdeskid[1]'', ''NVARCHAR (255)'') AS SourceName
            FROM @xmlData.nodes(''/journals/journal'') 
            xmlData(ref)) as Z

Bute When I Try this i get The error
Msg 8172, Level 16, State 1, Line 35
The argument 1 of the XML data type method "value" must be a string literal.

I think the problem ist the @xmlTag, but i donĀ“t know how i can make it dynamic :frowning:


WHy do you have double-quotes around the arguments to the value function?