Solved

SQL Server - Query help

Posted on 2013-06-26
7
428 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query to Add Late Tolerance 10 60
Error in query 3 52
Solution for warm standby SQL server 20 38
Generate Weekly Schedule 15 16
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

22 Experts available now in Live!

Get 1:1 Help Now