[dba-SQLServer] Use one field or another in query based on a condition

Francisco Tapia fhtapia at gmail.com
Thu May 19 13:20:33 CDT 2005


Try including the following Case statement...
if the PCCOrderNO = No Order then the NoOrder address will be displayed, 
otherwise the Order one will.


CASE RGA.PCCOrderNo = 'No Order' THEN NoOrderAddress.Address1
ELSE CustomerAddress.Sys_address_1
END AS NoOrdAdd1, 


On 5/19/05, Lavsa, Rich <Rich_Lavsa at pghcorning.com> wrote:
> 
> 
> In the Middle of the Select portion, you will see
> CustomerAddress.Sys_address_1 and at the end you will see
> NoOrderAddress.Address1 AS NoOrdAdd1. What can happen in this scenario
> is that sometimes the information is brought back from our ERP system in
> which the Order Number will return all the pertant information, however
> in very few cases I had to allow the entry of data even though there
> wasn't an Order number to refer to, so the information on a NO ORDER
> would be manually entered. So what I hope to achieve is to return the
> value CustomerAddress.Sys_address_1 if RGA.PCCOrderNo <> 'No Order' else
> return NoOrderAddress.Address1 AS NoOrdAdd1. I tried the ISNULL
> approach, Case statement, and an IF statement neither of which worked in
> returning a value that is inline, however all worked in testing for the
> condition and returning text but none acutally returned the field value
> when I ask it to return NoOrderAddress.Address1.
> 
> Any help would be greatly appreciated.
> 
> 


-- 
-Francisco
http://pcthis.blogspot.com |PC news with out the jargon!
http://sqlthis.blogspot.com | Tsql and More...



More information about the dba-SQLServer mailing list