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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:59:47+00:00 2026-05-28T00:59:47+00:00

I am writing an update statement where I need to update a list of

  • 0

I am writing an update statement where I need to update a list of items all at once with incremental dates. The incremental value is user defined. I found an example that is pretty similar to my needs at http://haacked.com/archive/2004/02/28/sql-auto-increment.aspx , but do not know how I would implement it. That example is:

DECLARE @counter int
SET @counter = 0
UPDATE #tmp_Users
SET @counter = counter = @counter + 1

My current statement is:

strSQL.CommandText = "Update tblItem set item_timed_close=convert(datetime, @item_timed_close),item_timed_start=convert(money, case when item_est_lo < 500 then ((convert(int,item_est_lo+25)/50)*50) when item_est_lo < 1000 then ((convert(int,item_est_lo+50)/100)*100) when item_est_lo < 3000 then ((convert(int,item_est_lo+125)/250)*250) when item_est_lo < 5000 then ((convert(int,item_est_lo+250)/500)*500) else ((convert(int,item_est_lo+12.5)/25)*25) end ) Where item_sale_id=@item_sale_id";
  strSQL.Parameters.Add(new SqlParameter("@item_timed_close", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "item_timed_close", DataRowVersion.Current, datetime_Var.AddMinutes(minutes_Var += Increments_var)));
  strSQL.Parameters.Add(new SqlParameter("@item_sale_id", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "item_sale_id", DataRowVersion.Current, itemSaleId3_Var));

datetime_Var is user defined, and is a DateTime format. minutes_Var equals zero to start with. Increments_var is user defined. I need item_timed_close to increment by whatever the Increments_var is set to.

EDIT

Results I am looking for would be something like this:

User specifies a starting date of 2012-01-08 12:00:00 PM and an increment of 10 seconds. For each row updated, the date would look like:

2012-01-08 12:00:00 PM
2012-01-08 12:00:10 PM
2012-01-08 12:00:20 PM
2012-01-08 12:00:30 PM
2012-01-08 12:00:40 PM
2012-01-08 12:00:50 PM
2012-01-08 12:01:00 PM
2012-01-08 12:01:10 PM
2012-01-08 12:01:20 PM

The first date could even have the incremented value already added to it for all we care, so long as it increments. I could change the initial starting date with that in mind through code.

Update

With Naval’s suggestion, I tried a sub query. First, I set all date fields to NULL. Then, I run the following query:

        strSQL3.CommandText = "Update tblItem set item_timed_close=DATEADD(minute,((Select count(*) as Count From tblItem Where item_sale_id=@item_sale_id And item_timed_close Is NULL) * @increment),convert(datetime, @item_timed_close)),item_timed_start=convert(money, case when item_est_lo < 500 then ((convert(int,item_est_lo+25)/50)*50) when item_est_lo < 1000 then ((convert(int,item_est_lo+50)/100)*100) when item_est_lo < 3000 then ((convert(int,item_est_lo+125)/250)*250) when item_est_lo < 5000 then ((convert(int,item_est_lo+250)/500)*500) else ((convert(int,item_est_lo+12.5)/25)*25) end ) Where item_sale_id=@item_sale_id";
        strSQL3.Parameters.Add(new SqlParameter("@item_timed_close", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "item_timed_close", DataRowVersion.Current, datetime_Var));
        strSQL3.Parameters.Add(new SqlParameter("@item_sale_id", SqlDbType.Int, 5, ParameterDirection.Input, true, 0, 0, "item_sale_id", DataRowVersion.Current, itemSaleId3_Var));
        strSQL3.Parameters.Add(new SqlParameter("@increment", SqlDbType.Int, 5, ParameterDirection.Input, true, 0, 0, "increment", DataRowVersion.Current, Increments_var));

I was hoping that I could multiply the sub query by the variable passed in, but it didn’t work as expected. It seems to multiply the @increment by 1 for every field. I’ve run the select statement alone and it returns 471. So I know that part works correctly. Do I need to cast Count as an integer or something?

DONE

I finally got it. I should have thought of this initially…. I had to change the counter variable in my update string’s regular Set sequence. Here is my working query.

 Declare @auto Int 
 Set @auto = 0 

 Update tblItem 
    set item_timed_close = DATEADD(minute, (@auto * @increment), convert(datetime, @item_timed_close))
      , item_timed_start = convert(money, 
                case when item_est_lo < 500  then ((convert(int, item_est_lo+25)/50)*50) 
                     when item_est_lo < 1000 then ((convert(int, item_est_lo+50)/100)*100) 
                     when item_est_lo < 3000 then ((convert(int, item_est_lo+125)/250)*250) 
                     when item_est_lo < 5000 then ((convert(int, item_est_lo+250)/500)*500) 
                     else ((convert(int,item_est_lo+12.5)/25)*25) end )
      , @auto = (@auto + 1) 
  Where item_sale_id=@item_sale_id

So I used the original example I had found, and just took out the last Set @counter part and put that into my update string’s set parameters.

  • 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-28T00:59:47+00:00Added an answer on May 28, 2026 at 12:59 am

    I finally got it. I should have thought of this initially…. I had to change the counter variable in my update string’s regular Set sequence. Here is my working query.

     Declare @auto Int Set @auto = 0 Update tblItem set item_timed_close=DATEADD(minute,(@auto * @increment),convert(datetime, @item_timed_close)),item_timed_start=convert(money, case when item_est_lo < 500 then ((convert(int,item_est_lo+25)/50)*50) when item_est_lo < 1000 then ((convert(int,item_est_lo+50)/100)*100) when item_est_lo < 3000 then ((convert(int,item_est_lo+125)/250)*250) when item_est_lo < 5000 then ((convert(int,item_est_lo+250)/500)*500) else ((convert(int,item_est_lo+12.5)/25)*25) end ),@auto = (@auto + 1) Where item_sale_id=@item_sale_id
    

    So I used the original example I had found, and just took out the last Set @counter part and put that into my update string’s set parameters.

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

Sidebar

Related Questions

I am writing a trigger and I need to use a statement level trigger.
I'm having difficulties writing what should be a simple SQL update statement in SQLAlchemy
I am writing a C# application that will update the fields in a SQL
When writing destructive queries (e.g., DELETE or UPDATE) in SQL Server Management Studio I
I'm writing an application that utilizes JavaScript timeouts and intervals to update the page.
I'm implementing a simple update mechanism for an application I'm writing the last part
I need help re-factoring this legacy LINQ-SQL code which is generating around 100 update
I am writing some tests for Javascript code and I need to dump some
I am writing a data warehouse, using MySQL as the back-end. I need to
I am a beginner SQL user (not formally trained; OJT only) and need some

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.