Solved

SQL Query of this Tables

Posted on 2011-03-09
8
263 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
 

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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

14 Experts available now in Live!

Get 1:1 Help Now