Sql server 2008在视图中加入查询

时间:2012-09-08 14:09:03

标签: sql sql-server-2008 jointable

请帮忙。我有以下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

错误消息是:

  

Msg 4104,Level 16,State 1,Line 2
  无法绑定多部分标识符“Item.Item_ID”   消息4104,级别16,状态1,行2   无法绑定多部分标识符“Auction.Item_ID”。

1 个答案:

答案 0 :(得分:4)

你在这一行上使用了错误的别名:

on Auction.Item_ID= Item.Item_ID 

您已将这些表格称为ab,因此您需要引用这些名称,将该行更改为:

on a.Item_ID= b.Item_ID 

所以你的完整查询将是:

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