我有一個沒有關係的表。當字段countyName是零長度字符串時,我需要Statewide
在結果集中。否則,我需要將該字段的值保持原樣,例如:請注意第二列中的'Statewide'和'countyName'。縣名應該是實際存儲在數據庫中的原始值。當SQL Server 2008的情況下
`countyName` `address`
blah blah
Jackson blah blah
必須(在這兩個例子中第一行是列名)
countyName address
Statewide blah blah
Jackson blah blah
這裏是我試過了,可以忽略其餘字段在這個例子中
select case servicetype
when 'cr' then 'Community Resource'
when 'ed' then 'Education'
when 'fb' then 'Faith-based'
when 'me' then 'Medical Equipment'
when 'hc' then 'Health Care'
else 'Other'
end as serviceType
,case countyName
when '' then 'Statewide'
else 'countyname' end
,name
,physicaladdress
,city
,statelocation
,zip
,phone
,website
from main
order by countyName, servicetype, name
什麼是與您的查詢問題?你有什麼錯誤嗎?意外的結果? –
查詢運行,但與第二個case語句,else不返回行中的原始值,一切都是'縣名' – wootscootinboogie
@MahmoudGamal屏幕帽編輯。 – wootscootinboogie