Link to home
Start Free TrialLog in
Avatar of Steve A
Steve AFlag for United States of America

asked on

Sql Server - XQuery [value()]: No more tokens expected at the end of the XQuery expression

Msg 2370, Level 16, State 1, Line 30
XQuery [value()]: No more tokens expected at the end of the XQuery expression. Found '1'.

Getting this error above when I do this select statement below.  Is there a better way to fix this XML PATH statement?
Thanks.
(Using Sql Server 2016)

select 7271 container_id into #cr_containers

(SELECT
      Stuff((
            SELECT N',' + cast(container_id as nvarchar(50))
            from #cr_containers
            FOR XML PATH(''),TYPE
      ).value('text()1','nvarchar(max)'),1,1,N''));
Avatar of Steve A
Steve A
Flag of United States of America image

ASKER

I think I figured it out, as seen below.  Added square brackets around the 'text()1'.

(SELECT
      Stuff((
            SELECT N',' + cast(container_id as nvarchar(50))
            from #cr_containers
            FOR XML PATH(''),TYPE
      ).value('text()1','nvarchar(max)'),1,1,N''));

Works fine now.

Thanks
Avatar of Steve A

ASKER

(SELECT
      Stuff((
            SELECT N',' + cast(container_id as nvarchar(50))
            from #cr_containers
            FOR XML PATH(''),TYPE
      ).value('text()[1]','nvarchar(max)'),1,1,N''));
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve A

ASKER

Thanks, will try it this way instead of my "band-aid".
Thanks again.