Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Query of this Tables

Posted on 2011-03-09
8
Medium Priority
?
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 41

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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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 41

Accepted Solution

by:
Sharath earned 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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