简体   繁体   English

Sql server 2008在视图中加入查询

[英]Sql server 2008 join query in a view

Please help. 请帮忙。 I have the below SQL code and it keeps getting errors: 我有以下SQL代码,它不断收到错误:

create view vwUpcoming
as 
    Select a.Auction_ID, b.item_name, b.Item_Description, 
        b.Item_value, a.Expected_Start_time
    from  Auction_schedule a 
    join Item b 
        on Auction.Item_ID= Item.Item_ID 
    where a.Expected_Start_Time < CURRENT_TIMESTAMP

The error message is: 错误消息是:

Msg 4104, Level 16, State 1, Line 2 Msg 4104,Level 16,State 1,Line 2
The multi-part identifier "Item.Item_ID" could not be bound. 无法绑定多部分标识符“Item.Item_ID”。
Msg 4104, Level 16, State 1, Line 2 Msg 4104,Level 16,State 1,Line 2
The multi-part identifier "Auction.Item_ID" could not be bound. 无法绑定多部分标识符“Auction.Item_ID”。

You are using the wrong aliases on this line: 您在此行上使用了错误的别名:

on Auction.Item_ID= Item.Item_ID 

You have called these tables either a or b so you need to reference those names, change the line to this: 您已将这些表调用为ab因此您需要引用这些名称,将该行更改为:

on a.Item_ID= b.Item_ID 

So your full query will be: 所以你的完整查询将是:

create view vwUpcoming
as 
    Select a.Auction_ID, b.item_name, b.Item_Description, 
        b.Item_value, a.Expected_Start_time
    from  Auction_schedule a
    join Item b 
        on a.Item_ID= b.Item_ID 
    where a.Expected_Start_Time < CURRENT_TIMESTAMP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM