SQL Table参数,过滤要插入的行

时间:2017-11-08 17:38:16

标签: sql sql-server

我有以下过程使用用户定义的表参数// Fill array by push() var arr1 = []; for (let i=0; i < 5; i++) { arr1.push(i); } console.log(arr1); // Fill array by assignment var arr2 = []; for (let i=0; i< 5; i++) { arr2[i] = i; } console.log(arr2);

@Till_Sales

有没有办法修改它,以便我只能插入ALTER PROCEDURE [dbo].[Create_Batch_Till_Sales] @Till_Sales [dbo].Till_Sale_Insert READONLY AS BEGIN SET NOCOUNT ON; INSERT INTO Till_Sale (Site_Lookup_Id, Client_Transaction_Date, Client_EOD_Id, Client_Id, Operator, PLU, Unit_Price, Quantity, Terminal_Id, Unit_Multiplier, Create_Date) SELECT tbl.Site_Lookup_Id, tbl.Client_Transaction_Date, tbl.Client_EOD_Id, tbl.Client_Id, tbl.Operator, tbl.PLU, tbl.Unit_Price, tbl.Quantity, tbl.Terminal_Id, tbl.Unit_Multiplier, GETDATE() FROM @Till_Sales AS tbl; END 表中当前不存在的参数表(@Till_Sales)中的行?我将使用Till_Sale列作为此实例中的唯一标识符。 SQL不是我最强的诉讼。

由于

2 个答案:

答案 0 :(得分:1)

ALTER PROCEDURE [dbo].[Create_Batch_Till_Sales]

@Till_Sales [dbo].Till_Sale_Insert READONLY
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO Till_Sale (Site_Lookup_Id, Client_Transaction_Date, Client_EOD_Id, Client_Id, Operator, PLU, Unit_Price, Quantity, Terminal_Id, Unit_Multiplier, Create_Date)
        SELECT tbl.Site_Lookup_Id, tbl.Client_Transaction_Date, tbl.Client_EOD_Id, tbl.Client_Id, tbl.Operator, tbl.PLU, tbl.Unit_Price, tbl.Quantity, tbl.Terminal_Id, tbl.Unit_Multiplier, GETDATE() 
        FROM @Till_Sales AS tbl
        WHERE NOT EXISTS (SELECT 1 FROM Till_Sale WHERE Till_Sale.Client_Id  = tbl.Client_Id)


END

答案 1 :(得分:0)

我设法对它进行排序......过了漫长的一天,不知道为什么我没有早点看到它!

ALTER PROCEDURE [dbo].[Create_Batch_Till_Sales]

@Till_Sales [dbo].Till_Sale_Insert READONLY
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO Till_Sale (Site_Lookup_Id, Client_Transaction_Date, Client_EOD_Id, Client_Id, Operator, PLU, Unit_Price, Quantity, Terminal_Id, Unit_Multiplier, Create_Date)
        (SELECT tbl.Site_Lookup_Id, tbl.Client_Transaction_Date, tbl.Client_EOD_Id, tbl.Client_Id, tbl.Operator, tbl.PLU, tbl.Unit_Price, tbl.Quantity, tbl.Terminal_Id, tbl.Unit_Multiplier, GETDATE() 
         FROM @Till_Sales AS tbl 
         WHERE tbl.Client_Id NOT IN (SELECT Client_Id FROM Till_Sale));

END