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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:24:17+00:00 2026-06-14T20:24:17+00:00

I have two tables, one is called Product and another one is called ProductVariant.

  • 0

I have two tables, one is called Product and another one is called ProductVariant. ProductVariant has ID from Product. I need to do simple operation on both tables.

Here is the query that I come up with:

declare @id int

declare cur CURSOR LOCAL for
select @id = ProductID  from Product WHERE (Published = '0')

open cur

fetch next from cur into @id 

while @@FETCH_STATUS = 0 BEGIN

UPDATE Productvariant SET Cost = SalePrice WHERE VariantID = @id;
UPDATE ProductVariant SET SalePrice = 0.00 WHERE VariantID = @id; 

fetch next from cur into @id 
END

close cur
deallocate cur

But it gives me:
Msg 154, Level 15, State 3, Line 4
variable assignment is not allowed in a cursor declaration.

Thanks

  • 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-14T20:24:18+00:00Added an answer on June 14, 2026 at 8:24 pm

    I would do something like this instead.

    SQL Fiddle

    MS SQL Server 2008 Schema Setup:

    create table Product
    (
      ProductID int,
      Published char(1)
    );
    
    create table ProductVariant
    (
      VariantID int,
      Cost money,
      SalePrice money
    );
    
    insert into Product values
    (1, '0'),
    (2, '1'),
    (3, '0')
    
    insert into ProductVariant values
    (1, 0, 10),
    (1, 0, 11),
    (2, 0, 20),
    (2, 0, 21),
    (3, 0, 30),
    (3, 0, 31);
    

    Query 1:

    UPDATE ProductVariant 
    SET    Cost = SalePrice, 
           SalePrice = 0.00 
    FROM   Product 
    WHERE  Product.ProductID = ProductVariant.VariantID AND
           Product.Published = '0';
    
    SELECT *
    FROM ProductVariant;
    

    Results:

    | VARIANTID | COST | SALEPRICE |
    --------------------------------
    |         1 |   10 |         0 |
    |         1 |   11 |         0 |
    |         2 |    0 |        20 |
    |         2 |    0 |        21 |
    |         3 |   30 |         0 |
    |         3 |   31 |         0 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: one called Projects, and another called Documents (projects has many
I have two tables, one called countries and one called country. Countries has both
I have two tables one called details and the other called c_details. Both tables
I have two tables on my database. One called room and another is called
I have two tables, one called PROJETO (id_projeto, id_tipo_projeto, descr_projeto, versao_projeto) and another called
I have two tables - one called customer_records and another called customer_actions . customer_records
I have two tables: one called styles, which has 5 attributes (plus id and
I currently have two tables, one is called games, the other called rounds. Here
I have two tables one called fs_note the other called dumy_fs_note I created after
i have two tables one is called addons and holds information about different addons,

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.