473,471 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can't get this darn thing to work!

3 New Member
I have a query where I'm trying to find all ProjectId's where a certain condition is met... The condition is that two records in a table are not in the correct sequence. In the results below, PREXTERNALID: APX04 should be 65 and is not in the correct sequence.

If I query the db for a single project, the results looks like this:
PREXTERNALID--PRID---PRPROJECTID--PRWBSSEQUENCE--PRWBSLEVEL
--------4---------- 5072393-----5005958------------------64---------------------------1
------APX04 -----5706280------5005958------------------63---------------------------2


So, to find out where this condition is true I wrote the following query to find where the value in PRWBSSEQUENCE for PREXTERNALID = APX04 is < the value in PRWBSSEQUENCE for PREXTERNALID = 4

SELECT PRPROJECTID FROM niku.PRTASK GROUP By PRPROJECTID
HAVING((
(SELECT PRWBSSEQUENCE
FROM niku.PRTASK
WHERE (CONVERT(Char(5),PREXTERNALID) = 'APX04') AND (PRPROJECTID = 5005958)
Group By PRPROJECTID,PRWBSSEQUENCE)
-
(SELECT PRWBSSEQUENCE
FROM niku.PRTASK
WHERE ((PREXTERNALID = '4.00') OR (PREXTERNALID = '4')) AND (PRPROJECTID = 5005958)
Group By PRPROJECTID,PRWBSSEQUENCE)
) < 0 AND (PRPROJECTID = 5005958))

If I don't include PRPROJECTID = 5005958 the query returns every record from niku.PRTASK table whether or not the condition is met. If I include the project id it will return the correct result but I want to find ALL that meet the condition in the table.

I'm seriously tearing my hair out over this one! Any help would be greatly appriciated!!!
Sep 29 '07 #1
3 1084
ck9663
2,878 Recognized Expert Specialist
I have a query where I'm trying to find all ProjectId's where a certain condition is met... The condition is that two records in a table are not in the correct sequence. In the results below, PREXTERNALID: APX04 should be 65 and is not in the correct sequence.

If I query the db for a single project, the results looks like this:
PREXTERNALID--PRID---PRPROJECTID--PRWBSSEQUENCE--PRWBSLEVEL
--------4---------- 5072393-----5005958------------------64---------------------------1
------APX04 -----5706280------5005958------------------63---------------------------2


So, to find out where this condition is true I wrote the following query to find where the value in PRWBSSEQUENCE for PREXTERNALID = APX04 is < the value in PRWBSSEQUENCE for PREXTERNALID = 4

SELECT PRPROJECTID FROM niku.PRTASK GROUP By PRPROJECTID
HAVING((
(SELECT PRWBSSEQUENCE
FROM niku.PRTASK
WHERE (CONVERT(Char(5),PREXTERNALID) = 'APX04') AND (PRPROJECTID = 5005958)
Group By PRPROJECTID,PRWBSSEQUENCE)
-
(SELECT PRWBSSEQUENCE
FROM niku.PRTASK
WHERE ((PREXTERNALID = '4.00') OR (PREXTERNALID = '4')) AND (PRPROJECTID = 5005958)
Group By PRPROJECTID,PRWBSSEQUENCE)
) < 0 AND (PRPROJECTID = 5005958))

If I don't include PRPROJECTID = 5005958 the query returns every record from niku.PRTASK table whether or not the condition is met. If I include the project id it will return the correct result but I want to find ALL that meet the condition in the table.

I'm seriously tearing my hair out over this one! Any help would be greatly appriciated!!!
do you reset count everytime PRPROJECTID change? or PRWBSSEQUENCE is sequential, like a record number?
Sep 29 '07 #2
papaparsons
3 New Member
do you reset count everytime PRPROJECTID change? or PRWBSSEQUENCE is sequential, like a record number?
No I don't think I do... I think what's wrong with the query is that it's not checking the "Having" clause for every record in PRTASK individually and returning those where the condition is met. What it is doing, is returning all records from the PRTASK table if the condition is met by any record in the table. What I need it to do, is return just the records where the condition is met. I hope that makes sense...
Sep 29 '07 #3
papaparsons
3 New Member
No I don't think I do... I think what's wrong with the query is that it's not checking the "Having" clause for every record in PRTASK individually and returning those where the condition is met. What it is doing, is returning all records from the PRTASK table if the condition is met by any record in the table. What I need it to do, is return just the records where the condition is met. I hope that makes sense...
I should have put this in there to show you what I think should be working but doesn't...

SELECT PRPROJECTID FROM niku.PRTASK GROUP By PRPROJECTID
HAVING((
(SELECT PRWBSSEQUENCE
FROM niku.PRTASK
WHERE (CONVERT(Char(5),PREXTERNALID) = 'APX04')
Group By PRPROJECTID,PRWBSSEQUENCE)
-
(SELECT PRWBSSEQUENCE
FROM niku.PRTASK
WHERE ((PREXTERNALID = '4.00') OR (PREXTERNALID = '4'))
Group By PRPROJECTID,PRWBSSEQUENCE)
) < 0 )

This query returns all records from PRTASK if the condition is met by any record in the table.
Sep 29 '07 #4

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

Similar topics

17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
6
by: Kylin | last post by:
Public Class test1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private...
6
by: Bob | last post by:
I'm trying to prevent the beep when the tab key is pressed. It works ok on XP but windows 2000 is ding ding ding Here is my code: Protected Overrides Function ProcessDialogKey(ByVal keyData As...
14
by: Bit byte | last post by:
I am pretty close to the end of my tether at the moment. I have a project which requires some header fies - which happen to be located in another folder (the relative path from where my sources...
7
by: John Salerno | last post by:
Whenever I turn an eye back toward website design, I find myself making frequent use of PHP's include function (or SSI's include directive). So I'm curious, is there a way to do this with Python...
7
by: clintonG | last post by:
To all Microsoft partners and customers who have been unable to download recently or access ASP.NET documentation from the msdn2 website and for all of those customers who have been lied to and...
22
by: J. Frank Parnell | last post by:
Hello, So, I was wondering how to do this: foreach($foo as $k=>$v AND $bar as $k2=>$v2){ echo '<TR><TD>$k</TD><TD>$v</TD><TD>$k2</TD><TD>$v2</TD></TR>; } Thanks,
9
by: cj | last post by:
Dim reqCustomerId As String = "uv$?????C??`?????C??@-?" If Val(reqCustomerId.Substring(0, 10) < 1111111111) Then the if gives me the error: Conversion from string "uv$?????C?" to type 'Double'...
7
by: otieatkins | last post by:
Hi. I have a really wonderful computer 3.6 ghz, 4 mb Ram, Intel Dual processor, Windows XP Sp3 - on paper. I don't think I have ever seen a system so slow. It takes forever to load up, forever for...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.