Solved

SQL Query of this Tables

Posted on 2011-03-09
8
264 Views
Last Modified: 2012-05-11
Attached one Excel file, which i stored one table records

I want to output of record which i defined in excel file.

Please check excel file and give me proper solutions.

Thank you.
Tablerecords.xls
0
Comment
Question by:citadelind
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:sameer_goyal
ID: 35092730
The information looks incomplete. I assume you want to fetch all records grouped on a particular customer?

Is that correct? If not, then let me know your filter creiterions and i will provide you the Sql query..
0
 

Author Comment

by:citadelind
ID: 35092749
Yes all records come form different tables like products,orders and customers.
So i am using with join query all three tables and make this output

but in product name, weight and price column are different and remaining are same records
so i want to put in one rows so i get output.

Please provide me query on this problem.

Thank you.
0
 
LVL 40

Expert Comment

by:Sharath
ID: 35092814
Try this.
SELECT DISTINCT Order#, 
                OrderDate, 
                PaymentType, 
                Price, 
                RTRIM(SUBSTRING(ISNULL((SELECT ',' + ProductName 
                                          FROM your_table t2 
                                         WHERE t1.Order# = t2.Order# 
                                        for xml path('')),' '),2,2000)) ProductName, 
                SUM([Weight]) 
                  OVER(PARTITION BY Order# )             [Weight], 
                ShipType, 
                ShipVia, 
                Company, 
                FirstName, 
                LastName, 
                [Address], 
                City, 
                [State], 
                Zip, 
                Country, 
                Phone, 
                Email, 
                Comments 
  FROM your_table t1

Open in new window

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:citadelind
ID: 35093310
Thank you for giving good query solution

But this query do not DISTINCT of the record. see the attach excel file which giving me output of result

It displays 2 record same.

Please give me solution.

Output.xls
0
 

Author Comment

by:citadelind
ID: 35094486
Please give me solution of about query

But this query do not DISTINCT of the record. see the attach excel file which giving me output of result

It displays 2 record same.

Please give me solution.


Output.xls
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 35102184
try this.
SELECT DISTINCT Order#, 
                OrderDate, 
                PaymentType, 
                SUM(Price) 
                  OVER(PARTITION BY Order# )                Price, 
                RTRIM(SUBSTRING(ISNULL((SELECT ',' + ProductName 
                                          FROM your_table t2 
                                         WHERE t1.Order# = t2.Order# 
                                        for xml path('')),' '),2,2000)) ProductName, 
                SUM([Weight]) 
                  OVER(PARTITION BY Order# )             [Weight], 
                ShipType, 
                ShipVia, 
                Company, 
                FirstName, 
                LastName, 
                [Address], 
                City, 
                [State], 
                Zip, 
                Country, 
                Phone, 
                Email, 
                Comments 
  FROM your_table t1

Open in new window

0
 

Author Comment

by:citadelind
ID: 35105985
Thank you for giving nice solutions.

It is working. Thank you.
0
 

Author Closing Comment

by:citadelind
ID: 35105991
Perfect ans.
0

Featured Post

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.

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.
In this article I will describe the Backup & Restore 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.
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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