0

这是查询(MS SQL):

use DB_432799_satv

select [DB_432799_satv].[dbo].ac_Orders.OrderNumber, OrderDate, PaymentDate, 
    CompletedDate, ShipDate,DateTimeFinishedPicking,DateTimeShipped, 
    ShipMethodName, PaymentMethodName
from [DB_432799_satv].[dbo].ac_Orders
Inner join [DB_432799_satv].[dbo].ac_Payments on 
    [DB_432799_satv].[dbo].ac_Orders.OrderId  = 
    [DB_432799_satv].[dbo].ac_Payments.OrderId
Inner join [DB_432799_satv].[dbo].ac_OrderShipments on  
    [DB_432799_satv].[dbo].ac_Orders.OrderId = 
    [DB_432799_satv].[dbo].ac_OrderShipments.OrderId
Inner join [DB_432799_satv].[dbo].[ac_Transactions] on 
    [DB_432799_satv].[dbo].ac_Payments.paymentid = 
    [DB_432799_satv].[dbo].ac_Transactions.paymentid
Inner join [SuperATV].[dbo].[tblPartsBoxHeader] on 
    [DB_432799_satv].[dbo].[ac_transactions].[ProviderTransactionId] = 
    [SuperATV].[dbo].[tblPartsBoxHeader].[ordernumber]

我如何将其更改为存储过程?

4

1 回答 1

1

我怀疑你想要的是“视图”会给你什么。具体来说,将该查询存储在数据库中并从中进行选择,例如:

SELECT * FOM myLongQueryView WHERE OrderNumber = 1234;

我不开发 MSSQL,但快速搜索在 msdn 上找到了这个文档页面。我想它会是这样的:

CREATE VIEW [DB_432799_satv].myLongQueryView
AS 
select [DB_432799_satv].[dbo].ac_Orders.OrderNumber, OrderDate, PaymentDate, 
    CompletedDate, ShipDate,DateTimeFinishedPicking,DateTimeShipped, 
    ShipMethodName, PaymentMethodName
from [DB_432799_satv].[dbo].ac_Orders
...

只需在查询前加上CREATE VIEW [DB_432799_satv].myLongQueryView AS,然后使用文档页面来决定是否需要任何选项。

重要的是要注意查询是存储的,而不是当前结果。因此,它会与您的数据保持同步。它是可连接的,可聚合的,等等......

于 2012-08-30T20:21:05.493 回答