Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8046813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:54:43+00:00 2026-06-05T05:54:43+00:00

I got this query: DECLARE @UserId INT DECLARE @StateChangeInformation XML SET @UserId = 1

  • 0

I got this query:

DECLARE @UserId INT
DECLARE @StateChangeInformation XML

SET @UserId = 1
SET @StateChangeInformation = '<stateChangeInformation EnableOverrideMarking="1"></stateChangeInformation>'
SET @command = 'DECLARE @UserIdXml XML; SET @UserIdXml = ''<userID>{ sql:variable("@UserId") }</userID>''; SET @StateChangeInformation.modify(''insert sql:variable("@UserIdXml") into (/stateChangeInformation)[1]'')'

EXEC sp_executesql @stmt = @command,
                   @params = N'@StateChangeInformation xml out',
                   @StateChangeInformation= @StateChangeInformation OUTPUT

SELECT @StateChangeInformation

What I want to do is to output the XML as:

<stateChangeInformation>
  <userID>1</userID>
</stateChangeInformation>

Currently, I am getting the following output:

<stateChangeInformation EnableOverrideMarking="1">
  <userID>"{ sql:variable("@UserId") }"</userID>
</stateChangeInformation>

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:54:45+00:00Added an answer on June 5, 2026 at 5:54 am

    You need to send @UserId as a parameter to the dynamic SQL and use concatenation to get the value in the XML.

    DECLARE @command nvarchar(max)
    DECLARE @UserId INT
    DECLARE @StateChangeInformation XML
    
    SET @UserId = 1
    SET @StateChangeInformation = '<stateChangeInformation EnableOverrideMarking="1"></stateChangeInformation>'
    SET @command = 'DECLARE @UserIdXml XML; 
                    SET @UserIdXml = ''<userID>''+cast(@UserId as varchar(10))+''</userID>''; 
                    SET @StateChangeInformation.modify(''insert sql:variable("@UserIdXml") into (/stateChangeInformation)[1]'')'
    
    EXEC sp_executesql @stmt = @command,
                       @params = N'@StateChangeInformation xml out, @UserId int',
                       @StateChangeInformation= @StateChangeInformation OUTPUT, @UserId = @UserId
    
    SELECT @StateChangeInformation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this Sql Query declare @ProductNo int set @ProductNo = 123 select o.OrderNo,
I've got this dynamic t-sql: declare @sql nvarchar(max) set @sql = N' insert into
i got this SQL query where post_title taken from $_GET $sql = SELECT ID
I have a query like this: use DataIncremental go DECLARE @row_terminator CHAR; SET @row_terminator
I have got this query: SELECT * FROM `mfw_navnode` n1 WHERE (n1.node_name='Eby' OR n1.node_name='Lana'
So I need to make 3 tabs with query (got this part down), but
Got this error on a big $_GET query in size ~9 000 symbols (they
I got this error running a query that goes against 2 tables with combined
I've got this array of usernames ['user1','user2'] and I want to query information about
I got a problem with this linq query: from PersistedFileInfo fi in m_Database from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.