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

x
?
Solved

Selecting distinct

Posted on 2008-10-31
3
Medium Priority
?
260 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

721 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