MS SQL query to update a table with the last entry in another table.

75 pts.
Tags:
Query
SQL
SQL queries
SQL Query
sql report
UPDATE statement
Hi, Could anyone please assist. I'm trying to update a Reporting Table with the last entry in another table. I've tried to arrange the table according to the ID row. This works great. Then the query to get the last entry woks as well, but to get the two to work together and update the table is a different story.

Answer Wiki

Thanks. We'll let you know when a new response is added.

I think you will need to be a little more specific in your question.

If you have a query that is not working, please post it here, and if possible, post your tables structure as well.

If you are getting some error message, let us know.
————-

What about trigger on that “another” table which will update the Reporting Table.

<b>More Info</b>

The query used to get the last information wrom the table is:

SELECT TOP 1 RemainingShifts
FROM TSProductionCal
ORDER BY ID DESC

Then to update the Reporting Template:

SET Datum = dbo.TSProductionCal.Datum,
Tyd = dbo.TSProductionCal.Tyd,
[Current_Prod_Shift] = dbo.TSProductionCal.[Current_Shft_Acc],
[Remaining_Prod_Shift] = dbo.TSProdbo.R_DEPENDENCYductionCal.RemainingShifts,
<annual_Shift_Remaining] = dbo.TSProductionCal.<annualDays_CntrU_Acc],
<annual_Shift_Completed] = dbo.TSProductionCal.<annualDays_CntrD_Acc],
[Production_Month] = dbo.TSProductionCal.[Production_Month_Acc]
FROM dbo.TSProductionCal
INNER JOIN dbo.[Report Template] ON dbo.[Report Template].ID = dbo.TSProductionCal.ID

Problem is that this copied all information to the Report Template and I just need it to Update the Last Value from the TSProduction Table

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    How about adding a where clause like this ? SET Datum = dbo.TSProductionCal.Datum, Tyd = dbo.TSProductionCal.Tyd, [Current_Prod_Shift] = dbo.TSProductionCal.[Current_Shft_Acc], [Remaining_Prod_Shift] = dbo.TSProdbo.R_DEPENDENCYductionCal.RemainingShifts, [Production_Month] = dbo.TSProductionCal.[Production_Month_Acc] FROM dbo.TSProductionCal INNER JOIN dbo.[Report Template] ON dbo.[Report Template].ID = dbo.TSProductionCal.ID WHERE dbo.TSProductionCal.ID = (SELECT max(ID) from dbo.TSProductionCal.ID) (But this will impact performance)
    69,240 pointsBadges:
    report
  • Ak282
    dear I have table with the name baseline learner having an learner bls_id field and second table with the name learner having bls_id field too.now i want to get bls_id field from baseline learner table and assign them to the learner bls_id in learners table.which query should i assign for that?
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following