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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:00:22+00:00 2026-05-27T14:00:22+00:00

I am creating a temp table from a query that generates data from SQL

  • 0

I am creating a temp table from a query that generates data from SQL functions. I would like to use this temp table to perform an insert for each row of data from the temp table. What is the best way to proceed with this?

#tmpTable is as follows (not all columns shown for simplicity):

EmpID       WorkHours      HourlyEquivalent     WeekOf
asmith      12             8.94                 12/5/2011
bjones      23.5           12.75                12/5/2011
criley      40             7.89                 12/5/2011

The table EmpHours will already be filled in with the employees hours but needs to be updated with their hourly equivalent (calculated from the aforementioned functions). I want to perform an UPDATE for each employee from the temp table as follows:

UPDATE EmpHours
SET HourlyEquivalent
WHERE WeekOf = #tmpTable.WeekOf
    AND EmpID = #tmpTable.EmpID

The number of UPDATEs I would need to perform is under 50 if that matters.

  • 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-27T14:00:23+00:00Added an answer on May 27, 2026 at 2:00 pm

    SQL is much more efficient at doing operations like this in a single command, instead of a row-by-row update. Even though you don’t have very many rows in this scenario, it’s still a good habit to take a set based approach instead of using a loop or a cursor.

    UPDATE e
    SET HourlyEquivalent = t.HourlyEquivalent
    FROM
        EmpHours e JOIN
        #tmpTable t ON t.WeekOf = e.WeekOf AND t.EmpID = e.EmpID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a temp table with a query like this: CREATE TEMPORARY TABLE
I'm creating a temp table that's the result of a stored procedure's result set.
I would like to understand this error I'm getting on a SQL Server 2005
I have a temp table set up like this: Type Rate TotalCost ---- ----
I have a temp table I am creating a query off of in the
Trying to migrate from MSSQL to MySQL. This Stored Proc is creating a temp
I'm creating a temp table and I want to fill the column from 0-9999
I'm using Microsoft SQL Server 2005. I'm creating a random record generator that will
Okay basically I am creating a stored procedure that will return data for our
In SQL Server 2008, I have table with records like these, Name ---- John

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.