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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:11:02+00:00 2026-05-23T17:11:02+00:00

Despite declaring a variable as type cursor when passing it to sp_executesql, I get

  • 0

Despite declaring a variable as type “cursor” when passing it to sp_executesql, I get the error “Operand type clash: nvarchar is incompatible with cursor”.

declare CURSOR_TO_PASS cursor for... --a simple select statement
--cursor opened, values obtained, etc...
declare @item nvarchar(5);
declare @seqno int;
--@item and @seqno populated
declare @sql nvarchar(400) = N'update MYTABLE set Survey' + cast(@seqno as nvarchar(2)) + N' = @itemvalue where current of @sc';
exec sp_executesql @sql, N'@itemvalue nvarchar(5), @sc cursor', @itemvalue = @item, @sc = CURSOR_TO_PASS;

I don’t know what’s wrong, because I’ve declare @sc as a cursor, and CURSOR_TO_PASS is a cursor, which I’m assigning to @sc when calling sp_executesql. So, is it possible to pass a cursor to sp_executesql?

  • 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-23T17:11:03+00:00Added an answer on May 23, 2026 at 5:11 pm

    I figured out the solution shortly after posting this. It is in fact possible to pass a cursor variable. There’s just an intermediate step required where you have to assign the cursor to a “cursor variable”, as demonstrated here: http://msdn.microsoft.com/en-us/library/ms190028.aspx “A cursor can be associated with a cursor variable by either of two methods:”, both of which require an initial, basic cursor variable declaration like “DECLARE @MyVariable CURSOR;”.

    So I added these lines to my code:

    declare @cursorvariable cursor;
    set @cursorvariable = CURSOR_TO_PASS;
    

    Then I changed @sc = CURSOR_TO_PASS to @sc = @cursorvariable, and it worked fine.

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

Sidebar

Related Questions

I got the error Use of unassigned local variable 'dictionary' despite I assigned the
Despite this being one of the best error messages I've ever seen (second only
Despite setting directory permissions to 777, I still can't get a PHP script to
Despite the other excellent answers here to similar posts, I cannot see the error
Despite many trials and errors, I cannot get the NumberTextBox widget to work. I
despite many tries I can't get the result that I would like to see
Despite using configuration below I got lazy initialize error: org.hibernate.LazyInitializationException: failed to lazily initialize
Despite primarily being a windows user, I am a huge fan of rsync. Now,
Despite an earlier question ( asked here ), our project is constrained to using
Despite having very little Linux experience, I'm too enticed by VPS (and too sick

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.