Solved

SQL Server - Query help

Posted on 2013-06-26
7
425 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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.
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now