Solved

Selecting distinct

Posted on 2008-10-31
3
224 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 500 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

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

895 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

16 Experts available now in Live!

Get 1:1 Help Now