Is it possible to use a nvarchar type sproc variable in an xquery insert statement within the stored procedure?
What I mean is something like this, in which an element is inserted only if a child element with the sought for value is present:
DECLARE @profiles_xml xml
DECLARE @profile_id int
DECLARE @user_id nvarchar(50)
SET @profile_id = 20
SET @user_id ='BC4A18CA-AFB5-4268-BDA9-C990DAFE7783'
SET @profiles_xml = (SELECT profiles from tbl_applied_profiles WHERE profiles.value('(Profile/ID)[1]','int')= @profile_id)
SET @profiles_xml.modify('
insert
if(/Profile/User/ID="user_id")
then <Activity>activity_name5</Activity>
else()
as first
into (/Profile/User/Activities)[1]')
The xml which @profiles_xml contains looks like this:
<Profile>
<ID>20</ID>
<User>
<ID>BC4A18CA-AFB5-4268-BDA9-C990DAFE7783</ID>
<Name>somename</Name>
<Activities>
<Activity>activity_name2</Activity>
</Activities>
</User>
</Profile>
You need to use
sql:variable("@user_id"), i.e.