Solved

SQL Server - Query help

Posted on 2013-06-26
7
430 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 65

Accepted Solution

by:
Jim Horn earned 500 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 8

Author Closing Comment

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Question 5 36
Rename SQL Instance/SQL Developer Edition 2012 2 21
Help  needed 3 26
MS SQL / SQL Server Native Client -- how to prevent seeing other servers? 2 25
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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