Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 存储过程中的串联_Sql_Sql Server_Stored Procedures - Fatal编程技术网

Sql 存储过程中的串联

Sql 存储过程中的串联,sql,sql-server,stored-procedures,Sql,Sql Server,Stored Procedures,我希望在存储过程中有类似的内容: InvoiceNumber = EventCode + EventInstance + EventCount 我不太确定如何将其编码到我的设置中(见下文)。我尝试了很多想法,但没有成功 ALTER PROCEDURE [dbo].[spInvoiceNumber] @EventCode nvarchar(10), @EventInstance nvarchar(10) AS BEGIN SET NOCOUNT ON; INSER

我希望在存储过程中有类似的内容:

InvoiceNumber =  EventCode + EventInstance + EventCount
我不太确定如何将其编码到我的设置中(见下文)。我尝试了很多想法,但没有成功

ALTER PROCEDURE [dbo].[spInvoiceNumber]
   @EventCode nvarchar(10),
   @EventInstance nvarchar(10)
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO Payment (EventCode, EventInstance, EventCount) 
    OUTPUT INSERTED.EventCode, INSERTED.EventInstance, INSERTED.EventCount
        SELECT 
            @EventCode, @EventInstance, ISNULL(MAX(EventCount), -1) + 1
        FROM 
            Payment 
        WHERE 
            (EventCode = @EventCode AND
             EventInstance = @EventInstance)
END

您可以尝试以下方法:

ALTER PROCEDURE [dbo].[spInvoiceNumber]
        @EventCode nvarchar(10),
        @EventInstance nvarchar(10)
AS

BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DECLARE @InvoiceNumber nvarchar(30) 

    declare @EventCount INT = 
    (select isnull(max(EventCount),-1) + 1
      FROM Payment 
      WHERE (EventCode = @EventCode AND
        EventInstance = @EventInstance)
    )

    SELECT @InvoiceNumber = @EventCode + @EventInstance + convert(nvarchar(10),@EventCount)

    INSERT INTO Payment (EventCode, EventInstance, EventCount, InvoiceNumber) 
    SELECT @EventCode, @EventInstance, @EventCount, @InvoiceNumber

END

为存储的数据创建输出参数procedure@cha你能举个例子吗?你的意思是在输出中再增加一行吗?e、 g.
INSERTED.EventCode+INSERTED.EventInstance+INSERTED.EventCount InvoiceNumber
?@cha InvoiceNumber为空。我需要从SELECT语句(EventCode、EventInstance和EventCount)中获取数据,并将其连接起来以提供InvoiceNumber。然后我想将EventCode、EventInstance、EventCount和InvoiceNumber插入我的付款表。
INSERT INTO Payment (EventCode, EventInstance, EventCount, InvoiceNumber) 
    OUTPUT INSERTED.EventCode, INSERTED.EventInstance, 
           INSERTED.EventCount, INSERTED.InvoiceNumber
    SELECT @EventCode, @EventInstance, 
           isnull(max(EventCount),-1) + 1,
           EventCode + EventInstance + CONVERT(VARCHAR(10), isnull(max(EventCount),-1) + 1)
    FROM   Payment 
    WHERE (EventCode = @EventCode AND
        EventInstance = @EventInstance)