Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the second or third element DYNAMICALLY of a XML document on XQuery with SQL Server


declare @X xml=
'<translations>
  <value lang="en-US">example</value>
  <value lang="1">Beispiel</value>
</translations>';

declare @Temp int
set @Temp=1
select @X.value('(/translations/value[@lang="'''+@Temp+'''"])[1]','varchar(max)');


What I have tried:

I tried to convert as varchar but it's not working.

select @X.value('(/translations/value[@lang="'''+cast( @Temp as varchar)+'''"])[1]','varchar(max)');
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900