Solved

SQL Query of this Tables

Posted on 2011-03-09
8
262 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL 2012 and SQL 2014 in memory database 11 32
Help with SQL Query 23 39
replication - alerts? 4 23
Error in query 3 0
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

12 Experts available now in Live!

Get 1:1 Help Now