Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Selecting distinct

Posted on 2008-10-31
3
Medium Priority
?
265 Views
Last Modified: 2012-05-05
Hello all
I have a view in my SQL Express database that looks like this
"SELECT     Stock_Code, Pallet_No, Weight, daterep, Trans, PONo
FROM         dbo.VW_SUPEXUSAGE01
WHERE     (daterep >= CONVERT(DATETIME, '22/10/2007', 103))"

This works fine but is there a way of creating the same view but making it pick up a single/disitnct pallet_no . There can be multiple pallets but i only want to pick up the first instance

Many thanks in advance
0
Comment
Question by:bostonste
3 Comments
 
LVL 8

Accepted Solution

by:
eszaq earned 2000 total points
ID: 22848513
Not sure what you are trying to achieve...

You might need to use WHERE clause (to select one particular Pallet_No):
"SELECT     Stock_Code, Pallet_No, Weight, daterep, Trans, PONo
FROM         dbo.VW_SUPEXUSAGE01
WHERE     (daterep >= CONVERT(DATETIME, '22/10/2007', 103))
   AND Pallet_No = ?yourVariableValue?"

OR you might need to use GROUP BY:
"SELECT     Pallet_No, Stock_Code, Weight, daterep, Trans, PONo
FROM         dbo.VW_SUPEXUSAGE01
WHERE     (daterep >= CONVERT(DATETIME, '22/10/2007', 103))
GROUP BY Pallet_No"

You can group by more then one column, but remember that columns in SELECT must be listed in the same exact order as in GROUP BY.

But the way you put your question it seems you need the first solution - WHERE clause.
0
 
LVL 8

Expert Comment

by:rpkhare
ID: 22848515
SELECT     Distinct Pallet_No, StockCode, Weight, daterep, Trans, PONo
FROM         dbo.VW_SUPEXUSAGE01
WHERE     (daterep >= CONVERT(DATETIME, '22/10/2007', 103))
0
 

Author Closing Comment

by:bostonste
ID: 31511973
ESZAQ
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

916 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