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 6989335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:11:54+00:00 2026-05-27T19:11:54+00:00

I’m having some trouble executing a dynamic query inside my SP, and I thought

  • 0

I’m having some trouble executing a dynamic query inside my SP, and I thought asking for some help as I can’t execute it correctly no matter what I try:

I have tried:

SET @subWorksQuery = 
'UPDATE JK_SubscriberWorks SET ' +
'update_date = convert(datetime, ''' + @dateNow + ''', 103), ' +
'challenge_' + convert(nvarchar(2), @challengeDay) + '_q = ''' + @challengeQuestion + ''', ' +
'challenge_' + convert(nvarchar(2), @challengeDay) + '_a = ''' + @challengeAnswer + ''' ' +
'WHERE subscriberwork_id = '' + convert(nvarchar(10), @subscriberWorksId) + '';';

execute @execReturn = @subWorksQuery

but I always get:

Msg 203, Level 16, State 2, Procedure sp_InsertChallengeResponse_test,
Line 112
The name ‘UPDATE JK_SubscriberWorks SET update_date = convert(datetime, ’23-12-2011 23:35:17’, 103), challenge_23_q =
‘Hvilket år blev Klasselotteriet omdannet til et aktieselskab?
Få hjælp til svaret.‘,
challenge_23_a = ‘1992’ WHERE subscriberwork_id = ‘ +
convert(nvarchar(10), @subscriberWorksId) + ‘;’ is not a valid
identifier.

Removing the UPDATE statement from that error and run it independently, it runs and performs the update


If I use sp_executesql like

SET @subWorksQuery = 
N'UPDATE JK_SubscriberWorks SET ' +
'update_date = @a, ' +
'challenge_' + convert(nvarchar(2), @challengeDay) + '_q = @b, ' +
'challenge_' + convert(nvarchar(2), @challengeDay) + '_a = @c ' +
'WHERE subscriberwork_id = @d;';

SET @parmDefinition = N'@a datetime, @b nvarchar(250), @c nvarchar(500), @d decimal';

execute sp_executesql 
             @subWorksQuery,
             @parmDefinition,
             @a = @CreateDate, @b = @challengeQuestion, @c = @challengeAnswer, @d = @subscriberWorksId;

It never performs the UPDATE, but does not throw any error.

What am I missing here?

  • 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-05-27T19:11:54+00:00Added an answer on May 27, 2026 at 7:11 pm

    Run it like this:

    execute (@subWorksQuery)
    

    [you won’t be getting anything back from the update statement in the variable, and you can’t run like this execute (@execReturn = @subWorksQuery) ]

    Without parentheses it seems to be starting parsing, assuming it is a stored procedure name, but failing when it hits the max length for one.

    In saying that, it is better to use sp_executesql with parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6

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.