2012-12-11 82 views
0

我有兩個conditions..i SQL結果需要在ASP同一列打印此兩個條件顯示它..檢查兩個SQL條件,並在同一列

SQL查詢

select P.[Port Name], CR.Name as country,CASE 
when SIH.[Ship-to Code] = '' then (select C.Name from [Customer] C where C.No_ = SIH.[Sell-to Customer No_]) 
end as name, 
case 
when SIH.[Ship-to Code] = '' then (select C.Address from [Customer] C where C.No_ = SIH.[Sell-to Customer No_]) 
end as addr, 
case 
when SIH.[Ship-to Code] = '' then (select C.[City] from [Customer] C where C.No_ = SIH.[Sell-to Customer No_]) 
end as city 
from [Sales Invoice Header] SIH, [Port] P, [Country_Region] CR where No_ = 'PEXP1213-523' and P.Code = SIH.Port 
and CR.Code = SIH.[Country of Final Destination] 
union all 
select P.[Port Name], CR.Name as country, 
case 
when SIH.[Ship-to Code] <> '' then (select C.Name from [Ship-to Address] C where C.Code = SIH.[Ship-to Code] and C.[Customer No_] = SIH.[Sell-to Customer No_]) 
end as name, 
case 
when SIH.[Ship-to Code] <> '' then (select C.[Address] from [Ship-to Address] C where C.Code = SIH.[Ship-to Code] and C.[Customer No_] = SIH.[Sell-to Customer No_]) 
end as addr, 
case 
when SIH.[Ship-to Code] <> '' then (select C.[City] from [Ship-to Address] C where C.Code = SIH.[Ship-to Code] and C.[Customer No_] = SIH.[Sell-to Customer No_]) 
end as city 
from [Sales Invoice Header] SIH, [Port] P, [Country_Region] CR where No_ = 'PEXP1213-524' and P.Code = SIH.Port 
and CR.Code = SIH.[Country of Final Destination] 
+0

請再具體些。你的SQL查詢是什麼? –

+0

這是我的SQL query..i我檢查等於空的條件,不等於空狀態......我得到了無論是在SQL中conditin結果......但我不能夠得到不等於空狀態asp .. – Affan

+0

不能製造混亂的頭部或尾部。選擇No_,確保它們都被找到。 PS你爲什麼不在第一次加入客戶,在第二次送貨地址? –

回答

2
select P.[Port Name], CR.Name as country, c.Name, c.Address, c.City 
from [Sales Invoice Header] SIH 
inner join Port P On P.Code = SIH.Port 
inner join Country_Region CR On CR.Code = SIH.[Country of Final Destination] 
inner join Customer C.No_ = SIH.[Sell-to Customer No_]) 
where No_ = 'PEXP1213-523' and SIH.[Ship_to Code] = '' 
union all 
select P.[Port Name], CR.Name as country, SIH.Name, SIH.Address,SIH.City 
From [Sales Invoice Header] SIH 
inner join Port P On P.Code = SIH.Port 
inner join Country_Region CR On CR.Code = SIH.[Country of Final Destination] 
Where No_ = 'PEXP1213-524' and SIH.[Ship_to Code] <> '' 

是一個更容易閱讀,並可能幫助你找出什麼是錯的。 使用ANSI連接語法,而不是前92的東西 和邪神的緣故,至少選擇一個命名約定爲您列和表。

哦,你可能必須在它所在的表中加上前綴No_,因爲我沒有線索。

+0

真的..很好..謝謝你..它工作正常..再次感謝你 – Affan

相關問題