Click here to Skip to main content
15,890,282 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL execution path question Pin
Andy Brummer20-Apr-05 9:53
sitebuilderAndy Brummer20-Apr-05 9:53 
GeneralRe: SQL execution path question Pin
Colin Angus Mackay20-Apr-05 9:55
Colin Angus Mackay20-Apr-05 9:55 
GeneralRe: SQL execution path question Pin
-Dr_X-21-Apr-05 5:59
-Dr_X-21-Apr-05 5:59 
GeneralInserting at a specific row Pin
Esmo200020-Apr-05 8:29
Esmo200020-Apr-05 8:29 
GeneralRe: Inserting at a specific row Pin
Colin Angus Mackay20-Apr-05 9:06
Colin Angus Mackay20-Apr-05 9:06 
GeneralA sytax question Pin
Esmo200020-Apr-05 8:05
Esmo200020-Apr-05 8:05 
GeneralRe: A sytax question Pin
Colin Angus Mackay20-Apr-05 9:08
Colin Angus Mackay20-Apr-05 9:08 
GeneralExecuting an UPDATE for each record returned by a SELECT Pin
Luis Alonso Ramos20-Apr-05 6:09
Luis Alonso Ramos20-Apr-05 6:09 
Hello,

Let's see if I can explain myself Smile | :) I have an Employees table with PK ID_employee. Then I have a Zones table with fields ID_zone, Description, and ID_employee (That's the employee that has been assigned that zone.)

I have another table, Receipts, where I have a list of receipts to collect for the week, with fields ID_receipt, ID_week (PK key into another table), ID_zone, ID_employee.

The idea is that before printing the receipts, I can change the employee assigned to the zone, and have it automatically changed for every receipt. So, after updating my Zones table, I can execute an UPDATE like this:
<code>DECLARE @@ID_employee int;
SELECT @@ID_employee = ID_employee FROM Zones WHERE ID_zone=@ID_zone;
UPDATE Receipts SET ID_employee=@@ID_employee WHERE ID_zone=@ID_zone AND ID_week=@ID_week;
(I know I could put both lines into one with something like a UPDATE Receipts SET ID_employee=(SELECT ID_employee FROM Zones... but for readability I left it as two queries.)

My question is how to automatically excute this UPDATE for all the record in Zones that match a certain criteria (specifically, that have not been marked as inactive -- another column.)

[EDIT: I just remembered about WHERE @ID_zone IN (SELECT ...) but in this case that could be added to the WHERE clause of the UPDATE, but how do I get the employee ID for the SET clause??]

Any ideas?

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: Executing an UPDATE for each record returned by a SELECT Pin
Colin Angus Mackay20-Apr-05 7:23
Colin Angus Mackay20-Apr-05 7:23 
GeneralRe: Executing an UPDATE for each record returned by a SELECT Pin
Luis Alonso Ramos20-Apr-05 8:11
Luis Alonso Ramos20-Apr-05 8:11 
GeneralRe: Executing an UPDATE for each record returned by a SELECT Pin
Colin Angus Mackay20-Apr-05 9:39
Colin Angus Mackay20-Apr-05 9:39 
GeneralRe: Executing an UPDATE for each record returned by a SELECT Pin
Luis Alonso Ramos20-Apr-05 13:02
Luis Alonso Ramos20-Apr-05 13:02 
GeneralRe: Executing an UPDATE for each record returned by a SELECT Pin
Colin Angus Mackay20-Apr-05 20:29
Colin Angus Mackay20-Apr-05 20:29 
GeneralData Source for Reporting Services Pin
azam31620-Apr-05 3:15
azam31620-Apr-05 3:15 
GeneralRe: Data Source for Reporting Services Pin
NewSilence23-Apr-05 13:17
NewSilence23-Apr-05 13:17 
GeneralRe: Data Source for Reporting Services Pin
azam31625-Apr-05 4:51
azam31625-Apr-05 4:51 
GeneralHey guys, Pin
Wilbur J. Pereira20-Apr-05 2:26
Wilbur J. Pereira20-Apr-05 2:26 
QuestionSQL Server : Add user login in a trigger? Pin
Duncan Edwards Jones20-Apr-05 0:12
professionalDuncan Edwards Jones20-Apr-05 0:12 
AnswerRe: SQL Server : Add user login in a trigger? Pin
Mike Dimmick20-Apr-05 1:23
Mike Dimmick20-Apr-05 1:23 
GeneralRe: SQL Server : Add user login in a trigger? Pin
Duncan Edwards Jones20-Apr-05 2:16
professionalDuncan Edwards Jones20-Apr-05 2:16 
Generalauotmatically generating a unique ID number [* Resolved *] Pin
steve_rm19-Apr-05 21:50
steve_rm19-Apr-05 21:50 
GeneralRe: auotmatically generating a unique ID number Pin
Mike Dimmick19-Apr-05 23:25
Mike Dimmick19-Apr-05 23:25 
GeneralRe: auotmatically generating a unique ID number Pin
totig22-Apr-05 2:20
totig22-Apr-05 2:20 
GeneralRe: auotmatically generating a unique ID number Pin
steve_rm22-Apr-05 13:27
steve_rm22-Apr-05 13:27 
Generalhelp - newbie needs help with sql problem Pin
squeakerz19-Apr-05 16:22
squeakerz19-Apr-05 16:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.