问题描述:

When I used this query above exception has thrown

SELECT FINQDET.InquiryNo,FINQDET.Stockcode,FINQDET.BomQty,FINQDET.Quantity,FINQDET.Rate,FINQDET.Required,FINQDET.DeliverTo,FSTCODE.TitleA AS FSTCODE_TitleA ,FSTCODE.TitleB AS FSTCODE_TitleB,FSTCODE.Size AS FSTCODE_Size,FSTCODE.Unit AS FSTCODE_Unit, FINQSUM.TITLE AS FINQSUM_TITLE,FINQSUM.DATED AS FINQSUM_DATED

FROM FINQSUM , FINQDET left outer join [Config]..FSTCODE ON FINQDET.Stockcode=FSTCODE.Stockcode

WHERE FINQDET.InquiryNo=FINQSUM.INQUIRYNO

ORDER BY FINQDET.Stockcode,FINQDET.InquiryNo

but if I used below query problem solved,

SELECT FINQDET.InquiryNo,FINQDET.Stockcode,FINQDET.BomQty,FINQDET.Quantity,FINQDET.Rate,FINQDET.Required,FINQDET.DeliverTo,FSTCODE.TitleA AS FSTCODE_TitleA ,FSTCODE.TitleB AS FSTCODE_TitleB,FSTCODE.Size AS FSTCODE_Size,FSTCODE.Unit AS FSTCODE_Unit,

FINQSUM.TITLE AS FINQSUM_TITLE,FINQSUM.DATED AS FINQSUM_DATED

FROM FINQSUM As FINQSUM , FINQDET As FINQDET left outer join [Config]..FSTCODE As FSTCODE ON FINQDET.Stockcode=FSTCODE.Stockcode

HERE FINQDET.InquiryNo=FINQSUM.INQUIRYNO

ORDER BY FINQDET.Stockcode,FINQDET.InquiryNo

Please can you explain Why using Alias better than using actual table names

网友答案:

The table [Config]..FSTCODE is qualified with database name which works fine if you use alias. Otherwise you need to qualify full name as it is from different database

网友答案:

Looks like FSTCODE is a table in a different DB. In the first query, though the JOIN uses the DB name to identify the table, the ON statement does not. The second statement adresses this by using an ALIAS

You can also modify the first statement as

left outer join [Config]..FSTCODE   
ON FINQDET.Stockcode=[Config]..FSTCODE.Stockcode
网友答案:

An alias allows you to reference a set without using the fullname. It saves you typing and allows you to express contextual information to the reader.

相关阅读:
Top