0

我正在尝试根据在Payment桌子上完成的付款创建发票视图。视图上的字段是和字段Balance之间的差异。当我插入付款表余额字段时显示为空。 AmountDueAmountPaid

 CREATE TABLE [dbo].[payment](
[AmountDue] [money] NULL,
[AmountPaid] [money] NULL,
[Balance] [money] NULL,
[CheckNumber] [varchar](50) NULL
) ON [PRIMARY]    

我的观点:

CREATE VIEW [dbo].[invoice]
AS
SELECT     AmountDue, AmountPaid, Balance AS [[AmountPaid-AmountDue]] AS Bal],   CheckNumber
FROM         dbo.payment

4

1 回答 1

1

你的语法不正确。现在,您正在返回Balance字段名称为(字面意思)的字段值"[AmountPaid-AmountDue]] AS Bal"

我想你想要:

CREATE VIEW [dbo].[invoice]
AS
SELECT     AmountDue, AmountPaid, AmountPaid-AmountDue AS Balance, CheckNumber
FROM         dbo.payment

虽然不清楚Balance物理Payment表上的字段应该如何应用,因为它在视图中被忽略了。

于 2013-11-12T15:22:24.050 回答