473,670 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correlated Query Summing Question.

2 New Member
I have a query that works just fine, but because I need to use it in Business Objects and I have to use a prompt for the date, I need the initial query for the count as a correlated subquery in the from clause, not in the select statement. I've figured out what I'd like to have, however, I only get one row back (and it is correct!) I need to get the results that the initial query gives me, which is about 10 rows. Is there any way I can do this? (I'm using MS SQL server)

Thanks!!
Susan
(Both queries are below)

Query I know works and am currently using:

select distinct
r.IndividualFir stResolve,
(select sum(n.NumberOfC alls)
from dbo.SolutionCen terTelephone n
where r.IndividualFir stResolve=n.Rec eiveCallName
AND substring((conv ert(char(6),n.c alldate,112)),1 ,7)=
(select max(substring(( convert(char(6) ,k.calldate,112 )),1,7))
from dbo.SolutionCen terTelephone k))
from dbo.HelpDeskTic ket r
where r.IndividualFir stResolve in (select distinct e.ReceiveCallNa me
from dbo.SolutionCen terTelephone e
where department='Hel pDesk')


What I'd like to have:

select distinct r.IndividualFir stResolve, ticketId as newcount
from dbo.HelpDeskTic ket r, dbo.SolutionCen terTelephone e
where
r.IndividualFir stResolve in (select e.ReceiveCallNa me
from dbo.SolutionCen terTelephone e
where department='Hel pDesk')
AND ticketId in (select sum(n.NumberOfC alls)
from dbo.SolutionCen terTelephone n
where IndividualFirst Resolve=n.Recei veCallName
AND substring((conv ert(char(6),n.c alldate,112)),1 ,7)=
(select max(substring(( convert(char(6) ,k.calldate,112 )),1,7))
from dbo.SolutionCen terTelephone k))
Apr 25 '06 #1
0 1915

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

Similar topics

0
14998
by: Murali | last post by:
Hi All I was reading thro the posting(s) of Thomas Kyte and his nifty approach to doing updates without the need for unnecessary correlated subqueries. An alternative to correlated subquery using this technique is: update ( select columnName, value from name, lookup
3
7337
by: David | last post by:
Consider this SQL Query: ----------------------------------------------------------------- SELECT c.CASE_NBR, DATEDIFF(d, c.CREATE_DT, GETDATE()) AS Age, c.AFFD_RCVD, c.PRV_CRD_ISS, x.RegE, x.Type, x.Fraud, c.CUST_FN + ' ' + c.CUST_LN AS CustFullName, c.ATM_CKCD_NBR, x.TotalLoss, x.Queue, x.Status, c.QUEUE AS Expr1, x.CHECK_ACT_NBR, c.CUST_LN, c.SSN, c.CREATE_DT FROM ( SELECT TOP 9999999 cl.CASE_NBR, cl.SSN, cl.CREATE_DT,
8
5096
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A WHERE EXISTS (SELECT 'X' FROM B, C WHERE B.COL1 = A.COL1 AND B.COL2 = A.COL2
1
2397
by: Mike MacSween | last post by:
tblProductions one to many to tblEvents tblEvents contains StartDate I want a report where the data are grouped by tblProductions.ProdID, and sorted by the earliest date in each Production. So this as a query (I've stripped out surplus fields): SELECT qryEvent.EventName, qryProduction.ProdName, qryEvent.ProdID,
8
2056
by: Howard, Steven | last post by:
I have created a web app that stores and displays all the messages from my database maintenance jobs that run each night. The web app uses Java servlets and has PostgreSQL 7.0 as the back end. When the user requests the first page, he gets a list of all the servers with maintenance records in the database, and a drop down list of all the dates of maintenance records. If the user chooses a date first, then the app uses a prepared...
0
2137
by: flamingo | last post by:
I have a query that works just fine, but because I need to use it in Business Objects and I have to use a prompt for the date, I need the initial query for the count as a correlated subquery in the from clause, not in the select statement. I've figured out what I'd like to have, however, I only get one row back (and it is correct!) I need to get the results that the initial query gives me, which is about 10 rows. Is there any way I can do...
4
3178
by: sql_server_user | last post by:
Hi, I have a history table with about 400 million rows, with a unique composite nonclustered index on two columns (object id and time period) which is used for most of the queries into the table, and an identity column for the clustered primary key. Many of my queries use correlated subqueries to pull unique history rows from the history table for each of a set of objects from the object table, for instance, pulling the earliest...
5
2235
by: steven.fafel | last post by:
I am running 2 versions of a correlated subquery. The two version differ slightly in design but differ tremendously in performance....if anyone can answer this, you would be awesome. The "bad" query attempts to build a result set using a correlated subquery. The part causing the error is that the correlated subquery is part of a derived table (joining 3 tables). Trying to run the query takes a long time and the more records in the...
4
2529
by: dancole42 | last post by:
So I have an invoicing database based on two main forms: Orders and OrderLines. Orders has fields like: OrderID BillingMethod OrderDate CreditCard CCExp OrdSubTotal ShippingCharge
0
8469
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4211
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
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 we have to send another system
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.