How can i use insert into myTABLE (. . . .. . ) select * from(.......)
. I try to write some linq query but i can not. Look please linq query.
SQL:
INSERT INTO ActualAmountsByLocation (ItemBarcode, Location, LocationName, Amount, isCustomerItem, LastUpdate)
SELECT * FROM
(SELECT DISTINCT
m.ItemBarcode,
m.ToLocationType + m.ToNo AS Location,
l.shortdesc AS LocationName,
dbo.spGetActualAmountByLocation(m.ItemBarcode, m.ToLocationType + m.ToNo) AS Amount,
0 AS isCustomerItem,
GETDATE() AS LastUpdate
FROM
dbo.StockMovement m, RefLocations l
WHERE
m.ToLocationType = 'L'
AND m.ToLocationType + m.ToNo = l.code
AND m.ItemBarcode = @Barcode
AND m.TransactionType = 1
) a
ORDER BY ItemBarcode, Location
UPDATE ActualAmountsByLocation
SET isCustomerItem = 1
WHERE ItemBarcode IN
(SELECT barcode FROM StockMaterials WHERE barcode = @Barcode AND ownership = 1)
UPDATE ActualAmountsByLocation
SET isCustomerItem = 1
WHERE ItemBarcode IN
(SELECT barcode FROM StockTools WHERE barcode = @Barcode AND ownership = 1)
UPDATE ActualAmountsByLocation
SET isCustomerItem = 1
WHERE ItemBarcode IN
(SELECT barcode FROM StockComponents WHERE barcode = @Barcode AND ownership = 1)
SET @ReturnMsg = RTRIM(@ReturnMsg) + 'E25: Transaction completed successfully ' + CHAR(13) + CHAR(10)
Linq:
if (ToLocationType == 'L')
{
var stokRefLocation = (from m in stockMovementCtx.StockMovements
from l in stockMovementCtx.RefLocations
where m.ToLocationType == 'L' && m.ToLocationType + m.ToNo == l.code && m.ItemBarcode == Barcode && m.TransactionType == 1
orderby m.ItemBarcode, l.shortdesc
select new
{
myItemBarcode= m.ItemBarcode,
myLocation = m.ToNo + m.ToNo,
myLocationName = l.shortdesc,
myAmount = stockMovementCtx.spGetActualAmountByLocation(m.ItemBarcode, m.ToLocationType + m.ToNo),
myIsCustomerItem = 0,
myLastUpdate = DateTime.Now
}).Distinct();
var stokMovement2 = new ActualAmountsByLocation()
{
ItemBarcode = stokRefLocation. //.. how can i do that? I want to see stokRefLocation.myItemBarcode
}
}
}