由于我在过去13年中一直使用SQL Server。现在,我想与Eloquent(ORM)一起使用Laravel框架。我在SQL Server 2008中使用了“合并语句”。我想知道如何在Eloquent(ORM)中使用此功能。
我有检查文档,但找不到任何解决方案,请检查下面的SQL merge语句并建议如何在Eloquent中执行此功能
Merge OrderStyleDetail as [Target]
Using @StyleMstDetail as [Source]
On [Target].[OrderNo] = [Source].[OrderNo] And [Target].LocationId=[Source].LocationId and [Target].SingleMstTypeId=[Source].SingleMstTypeId
When Not Matched Then Insert (OrderNo,LocationId,ItemId,StyleMstId,SingleMstTypeId,SingleMstId,UserName,SysName) Values (@OrderNo,@LocationId,@ItemId,[Source].StyleMstId,[Source].SingleMstTypeId,[Source].ValueId,@UserName,@SysName)
When Matched Then UpDate Set ItemId=@ItemId,StyleMstId=[Source].StyleMstId,SingleMstId=[Source].ValueId,SingleMstTypeId=[Source].SingleMstTypeId
When Not Matched by Source And [Target].OrderNo=@OrderNo And [Target].LocationId=@LocationId Then Delete;