Sql Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sri Ganesh
    New Member
    • Jun 2013
    • 7

    Sql Query

    Hi,

    I have a table like this

    Code:
    CompanyName Addresstype Name  Addressline1       City     Country
    ABC         Billing     John  252,Green street   Chicago  USA
    ABC         Shipping    Jacob 152,Blue street    Chicago  USA
    ABC         Contact     Jerry 102,yellow street  Chicago  USA
    XXX         Billing     Rose  252,Green street   Newyork  USA
    XXX         Contact     Ajay  102,yellow street  Newyork  USA
    yyy         Shipping    Pooja 252,Green street   Washington  USA
    yyy         Contact     Jack  102,yellow street  Washington  USA
    ZZZ         Contact     jath  252,Green street   Newjercy  USA
    
    if the table have billing addresstype then show only billing addresstype,
    else if table have Shipping addresstype then show only billing addresstype
    else Contact addresstype.
    
    for example:-
     if i give CompanyName='ABC' then show only billing address
     Like
    CompanyName Addresstype Name  Addressline1       City     Country
    ABC         Billing     John  252,Green street   Chicago  USA
    
    if  CompanyName='yyy'
    CompanyName Addresstype Name  Addressline1       City     Country
    yyy         Shipping    Pooja 252,Green street   Washington  USA
    
    if  CompanyName='ZZZ'
    CompanyName Addresstype Name  Addressline1       City     Country
    ZZZ         Contact     jath  252,Green street   Newjercy  USA
    Contact addresstype is must but we give 1st preference to billing then shipping then only
    contact.

    I want to display only one row but dont use top function..

    Thanks in advance...

    Regards,
    Sri Ganesh
    Last edited by Rabbit; Jun 28 '13, 03:41 PM. Reason: Please use code tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Why can't you use the top function?

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Do you have a PK on this table? Or another table that act as dimension table for the company information?

      ~~ CK

      Comment

      Working...