创建我的第一个SQL Server存储过程

时间:2015-03-19 17:11:42

标签: sql sql-server stored-procedures

我想创建一个存储过程,打印出一条消息,列出所有客户及其未付款的contactNum。我希望它看起来像管理员的报告。我不知道如何解决这个问题,所以任何帮助都会很棒!

我已经为此创建了一个查询,但我仍然坚持如何创建存储过程。

以下是查询:

SELECT 
    booking.bookingID,
    booking.totalCost,
    booking.bookingDate,
    booking.paymentConfirmation,
    customers.customersID,
    customers.firstname,
    customers.surname,
    customers.contactNum
FROM 
    booking 
INNER JOIN 
    customers ON booking.customerID = customers.customersID
WHERE
    paymentConfirmation = 'False'
ORDER BY 
    bookingDate ASC

由于您的耐心,我对存储过程的了解非常少。

2 个答案:

答案 0 :(得分:1)

尝试:SEE HERE

USE zachtravelagency
CREATE PROCEDURE dbo.mySP1
AS 

    SELECT 
    booking.bookingID,
    booking.totalCost,
    booking.bookingDate,
    booking.paymentConfirmation,
    customers.customersID,
    customers.firstname,
    customers.surname,
    customers.contactNum


    FROM booking INNER JOIN customers
    ON booking.customerID= customers.customersID

    Where
    paymentConfirmation = 'False'

    ORDER BY bookingDate ASC
GO

答案 1 :(得分:1)

以下是您要求的完整代码

USE zachtravelagency
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROC [dbo].[GetAdminReport] 
AS 
 BEGIN
 SELECT 
booking.bookingID,
booking.totalCost,
booking.bookingDate,
booking.paymentConfirmation,
customers.customersID,
customers.firstname,
customers.surname,
customers.contactNum


FROM booking INNER JOIN customers
ON booking.customerID= customers.customersID

Where
paymentConfirmation = 'False'

ORDER BY bookingDate ASC


END
GO