sql >> Database >  >> RDS >> Sqlserver

Is er een manier om rijen tegelijkertijd te SELECTEREN en BIJWERKEN?

Overweeg om de OUTPUT-clausule te bekijken :

USE AdventureWorks2012;  
GO  

DECLARE @MyTableVar table(  
    EmpID int NOT NULL,  
    OldVacationHours int,  
    NewVacationHours int,  
    ModifiedDate datetime);  

UPDATE TOP (10) HumanResources.Employee  
SET VacationHours = VacationHours * 1.25,  
    ModifiedDate = GETDATE()   
OUTPUT inserted.BusinessEntityID,  
       deleted.VacationHours,  
       inserted.VacationHours,  
       inserted.ModifiedDate  
INTO @MyTableVar;  

--Display the result set of the table variable.  
SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate  
FROM @MyTableVar;  
GO  
--Display the result set of the table.  
SELECT TOP (10) BusinessEntityID, VacationHours, ModifiedDate  
FROM HumanResources.Employee;  
GO 


  1. Verwijder alle opgeslagen procedures in MySQL of gebruik tijdelijke opgeslagen procedures

  2. Toegang geweigerd fout bij gebruik van mysql_real_escape_string()

  3. Rijen ophalen uit meerdere tabellen met UNION ALL of één tabel in productie gebruiken?

  4. SYS_GUID() Functie in Oracle