COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
INSERT INTO TBLORDERDETAILSHIST
SELECT * from
tblOrderDetails
ORDER BY OrderID ASC
5.7.3. Insert vaøo baûng laáy giaù trò cuï theå, baûng khaùc:
INSERT INTO <Tablename1>[<columnname list>]
Select [columnname list], valueslist
From <Tablename2>
Where <conditions>
ORDER BY <column name> ASC/DESC
Ví duï 8-18: INSERT vaøo baûng töø giaù trò cuï theå, baûng khaùc
/* Theâm maåu tin vôùi caùc coät cuï theå */
/* Chuyeån taát caû nhöõng hôïp ñoàng chi tieát töø baûng tblOrderDetails vaøo baûng tblOrderDetailsHist. Giaû söû
raèng, ngoaøi nhöõng coät gioáng nhö tblOrderDetails, baûng tblOrderDetailsHist coøn coù theâm coät Tranferdate.
*/
INSERT INTO
TBLORDERSHIST(
OrderID,
OrderDate,
ReceiveFolio,
CustID,
Descriion,
Amount,
Historydate)
SELECT
OrderID,
OrderDate,
ReceiveFolio,
CustID,
Descriion,
Amount,
getdate() as Historydate
From tblOrders
where Month(OrderDate)=12
Order by OrderDate,CustID
/* Coù theå vieát laïi theâm maåu tin vôùi taát caû caùc coät nhö sau */
/* Chuyeån taát caû nhöõng phieáu thu trong thaùng 12 töø baûng tblOrders vaøo baûng tblOrdersHist vôùi ñieàu kieän
soá coät töông öùng trong baûng tblOrders baèng vôùi soá coät trong baûng tblOrdersHist, baïn coù theå vieát laïi nhö
sau */
INSERT INTO
TBLORDERDETAILSHIST(
ItemID,
OrderID,
No,
Qtty,
Price,
Discount,
Amount,TranferDate)
SELECT
ItemID,
Giaùo vieân: Phaïm Höõu Khang