Solved

Selecting distinct

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

821 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