473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query for specific duplicated values

dbrewerton
115 New Member
Ok, let me see if I can explain this clearly. What I'm trying to do is generate a query that looks for duplicate start times. The caveat here is there are certain character strings that have to be present for it to be considered a duplicate. Here is the existing query I have:

Expand|Select|Wrap|Line Numbers
  1. SELECT AL2.PS, AL2.ASSETS, AL2.PT, AL2.NP, AL2.NN, AL2.AS, AL2.PR, AL2.CH1, AL2.AT, AL2.AD, AL2.PC,  AL2.PE, AL2.STAT, AL2.SYS, AL2.BD, AL2.LOC, AL2.IR FROM MYDB AL2
  2. WHERE (PS >= CAST(
  3. FLOOR( CAST( GETDATE() AS FLOAT ) )
  4. AS DATETIME
  5. )+1) AND (PS < CAST(
  6. FLOOR( CAST( GETDATE() AS FLOAT ) )
  7. AS DATETIME
  8. )+14) AND ST <> 'CL';
Ok, now the duplication will be based on AL2.PS and the AL2.ASSETS field must contain certain codes in it to be considered a duplicate.

Example:
If record 1 has a PS = 2010-11-15 15:30:00 and has an ASSET code of JPB, find any records that match that time in this table. The idea is I'm looking for duplicated records in the same table. I have been working on this and I am stumped.
Nov 15 '10 #1
5 1443
amitpatel66
2,367 Recognized Expert Top Contributor
How about:
Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  with t as (SELECT '2010-11-15 15:30:00' ps,'JPB' asset from dual
  5.   2  union all select '2010-11-15 15:30:00','JPB' from dual
  6.   3  union all select '2010-11-15 15:30:32','JPB' from dual)
  7.   4  select ps,asset,COUNT(*) cnt
  8.   5  FROM   t
  9.   6  GROUP BY ps,asset
  10.   7* HAVING COUNT(*) > 1
  11. SQL> /
  12.  
  13. PS                  ASS        CNT
  14. ------------------- --- ----------
  15. 2010-11-15 15:30:00 JPB          2
  16.  
  17. SQL> 
  18.  
  19.  
Nov 16 '10 #2
dbrewerton
115 New Member
Thank you, I will give that a shot! :)
Nov 16 '10 #3
dbrewerton
115 New Member
What is Dual supposed to be? Got a large result dating back to 2009. I want only 14 days of data into the future.
Nov 16 '10 #4
amitpatel66
2,367 Recognized Expert Top Contributor
Can you post what you are trying?

Btw, Dual is a dummy table that I used to create dummy data becauase I dont have a table that you are using.
Nov 17 '10 #5
dbrewerton
115 New Member
Ok, what I am trying to accomplish is as follows:
based on a sub query that finds certain items that must run without interruption, I want to have a query that will return results that would cause a time conflict. The subquery I am using is:

Expand|Select|Wrap|Line Numbers
  1. SELECT START, END, NUMBER, CHAR1, PROJECT, DEPT, CATEGORY 
  2. from MyDB 
  3. WHERE START between  (CAST(FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME)+1) 
  4. AND (CAST(FLOOR( CAST( GETDATE() AS FLOAT ) ) AS DATETIME)+7)
  5. AND CATEGORY = 'MAIN'
  6. AND CHAR1 = 'YES'
  7.  
Now, the prime difference is the ones I'm looking for would be CHAR1 as NO or NULL. The conflict would be related to the duration. None of the non-char1 tasks can be ran during the duration. Here is a sample result set:

Expand|Select|Wrap|Line Numbers
  1. START                    END                NUMBER    CHAR1    PROJECT     DEPT    CATEGORY
  2. 2010-11-20 23:00:00    2010-11-21 04:00:00    18688    YES    Project1    DEPT1    MAIN
  3. 2010-11-21 23:00:00    2010-11-22 00:00:00    19933    YES    Project2    DEPT2    MAIN
  4. 2010-11-19 00:00:00    2010-12-17 00:00:00    25652    YES    Project3    DEPT3    MAIN
  5.  
Nov 18 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1850
by: Jerry | last post by:
Hi, Access 2003. I would like to query specific dates or years. I need to be able to selct the dates in a query, ie aug 12 2004, aug 11th 2004, or 2001, 2002 and 2003. Any help is most appreciated
1
2554
by: carrionk | last post by:
Hi, I have created a Subform which SourceObject is a parameter query. This is the Query: Qry Name:80IsscomProduct SELECT * FROM Isscomp28 WHERE Like ;
0
1022
by: YuanYuan | last post by:
Thank you so much, guys. I really appreciate that. >-----Original Message----- >Hi, I am wondering if there is a nice way to elimate >duplicated values in an array, just like the "unique"...
3
30268
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
9
7965
by: bubbles | last post by:
Newbie transiting from VBA to TSQL, using SQL Server 2005 Enterprise: Need help to do this: Open Table_A WITH TableA DO UNTIL .EOF Read value from TableA.ColumnA Run SQL Statement on...
2
12055
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
2
3713
by: gerrybytes | last post by:
Is the following a vaild query, or does any one have any suggestion on how to change it to get the correct info i'm looking for? $Engineer = $_POST; $Ref_No = $_POST; $query = "INSERT INTO...
6
3024
by: asp2 | last post by:
I have a cursor inside a program unit in Oracle Forms 6 and its supposed to get one row from this cursor .. but in some values (only some and others not) it gets the same row twice (duplicated) in...
6
19780
by: Suevans | last post by:
I've written a basic query which has a calculated field Amount: - The query works fine. Sometimes it will not have anything to show, this is correct, it is for unreconciled transactions. ...
2
17599
by: Marcin W | last post by:
Hi, I have following problem. I have to run a query where one of the result fields should be within range of values I got from different table. Query 1 select column_x from table1 where...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.