Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server - Query help

Posted on 2013-06-26
7
Medium Priority
?
440 Views
Last Modified: 2013-06-26
Hello Experts,

 I have this SQL Query:

Select A.AddressName, A.NameFirst,A.NameLast, A.Address1, A.Address2,
A.City, A.StPrId, A.PostalCode from edgePier1.dbo.OrderHeader OH
JOIN edgePier1.dbo.Addresses A
ON OH.MemberId = A.MemberId
Where OH.OrderHeaderId = 54000329

Results:

AddressName NameFirst NameLast Address1 Address2 City      StPrId PostalCode


Shipping address 1      John      Seabaugh      123 E Main St      NULL      Grandview      60      76050-1903

Billing address      John      Seabaugh      123 E Main St      NULL      Grandview      60      76050-1903


 i want to write a SQL that will show Billing and shipping address on the same line(single line.)

any idea?

Thanks
0
Comment
Question by:mani_sai
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 39278379
Select REPLACE(REPLACE(A.AddressName,CHAR(13),''),CHAR(10),''), A.NameFirst,A.NameLast, A.Address1, A.Address2, 
A.City, A.StPrId, A.PostalCode from edgePier1.dbo.OrderHeader OH 
JOIN edgePier1.dbo.Addresses A 
ON OH.MemberId = A.MemberId
Where OH.OrderHeaderId = 54000329

Open in new window

0
 
LVL 8

Author Comment

by:mani_sai
ID: 39278407
your query is showing results on 2 lines...

I want shipping and billing information on the same line....
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 39278412
Is there a column in dbo.addresses that uniquely identifies the customer?

If so, then it would be a subquery that goes something like this <air code, replace the obvious>...

SELECT
 sa.NameFirst as ship_NameFirst,
 sa.NameLast as ship_NameLast,
 sa.Address1 as ship_Address1,
 sa.Address2 as ship_Address2,
 sa.City as ship_City,
 sa.StPrId as ship_StPrId,
 sa.PostalCode as ship_PostalCode,
 ba.NameFirst as bill_NameFirst,
 ba.NameLast as bill_NameLast,
 ba.Address1 as bill_Address1,
 ba.Address2 as bill_Address2,
 ba.City as bill_City,
 ba.StPrId as bill_StPrId,
 ba.PostalCode as bill_PostalCode
FROM edgePier1.dbo.OrderHeader OH
    JOIN ( SELECT AddressName, etc FROM Address WHERE AddressName = 'Shipping Address') sa ON oh.ThatColumn = sa.ThatColumn
    JOIN ( SELECT AddressName, etc FROM Address WHERE AddressName = 'Billing Address') ba ON oh.ThatColumn = ba.ThatColumn
Where OH.OrderHeaderId = 54000329
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Author Closing Comment

by:mani_sai
ID: 39278464
Great. It worked. Thanks.
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39278478
Thanks for the grade.  Good luck with your project.  -Jim
0
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 39278483
Sorry, my mistake. Thought you were trying to remove a carriage return, line feed.
0
 
LVL 8

Author Comment

by:mani_sai
ID: 39278556
EvilPostIt - no problem.

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question