Help Make Query Run Better (faster)

Mar 20, 2007

I need help makeing the following query run more efficently.


Code:


SELECT t1.ID,t1.firstName,t1.lastName,t1.address,t1.city,t1.state, t1.zip,t1.locationAddress,t1.locationCity,t1.locationState,t1.locationZip
FROM Landlord_tbl t1
left outer join Mail_tbl t2
ON t2.potentialSitesID = t1.potentialSitesID
WHERE t2.mailed_out_date is null and NOT(t1.firstName+t1.lastName) is Null
GROUP BY t1.ID,t1.firstName,t1.lastName,t1.address,t1.city,t1.state, t1.zip,t1.locationAddress,t1.locationCity,t1.locationState,t1.locationZip
ORDER BY t1.firstName, t1.lastName, t1.city, t1.state

View 3 Replies


ADVERTISEMENT

Any Clue To Make This Query Run Faster

Oct 3, 2006

Any help would be really appreciated....
My stored procedure...




CREATE PROCEDURE business3rd7
@Fromdate DATETIME,
@ToDate DATETIME
AS



select distinct CONVERT(VARCHAR(10),Receipts.Companynumber1)+CONVE RT(VARCHAR(10),Receipts.Companynumber2) as co ,
Receipts.Premium1+Receipts.Premium2 as Premium,
"CAN"=case when Receipts.transactiontype='CAN'
then (receipts.premium1+receipts.premium2)
else 0
end,
"NET"=Receipts.Premium1+Receipts.Premium2-case when Receipts.transactiontype='CAN'
then (receipts.premium1+receipts.premium2)
else 0
end,

"#NEW"=case when Receipts.transactiontype='NEW' then count(Receipts.policynumber) else
0 end,

-------
"$NEW"=
case when Receipts.transactiontype='NEW' then (Receipts.Premium1+Receipts.premium2)
else 0 end,
"#REN"=case when Receipts.transactiontype='REN' then count(Receipts.policynumber) else
0 end,
"$RENEW"=
case when Receipts.transactiontype='REN' then (Receipts.Premium1+Receipts.premium2)
else 0 end,
"#AP"=case when Receipts.transactiontype='AP' then count(Receipts.policynumber) else 0
end,
"$AP"=
case when Receipts.transactiontype='AP' then (Receipts.Premium1+Receipts.premium2) else
0 end,
"#SENT"=case when policy.Renewalofferdate between @Fromdate AND @ToDate then
count(policy.policynumber) end,

"%"=case when case when Receipts.transactiontype='REN' then count(Receipts.policynumber)else 0
end =0 then 0
when case when policy.Renewalofferdate between @Fromdate AND @ToDate then
count(policy.policynumber) else 0 end=0 then 0
else
case when Receipts.transactiontype='REN' then count(Receipts.policynumber)else 0
end /case when policy.Renewalofferdate between @Fromdate AND @ToDate then
count(policy.policynumber) else 0 end end,


"Current Year"= case when policy.Renewalofferdate between @Fromdate AND @ToDate then
count(clubamount) end,
"Previous Year"=case when policy.Renewalofferdate between DateAdd(year, -1, @Fromdate)
AND DateAdd(year, -1, @ToDate) then count(clubamount) end,
"#AA"=count(receipts.clubamount),
"$AA"=sum(receipts.clubamount)

FROM Receipts,Policy
where Receipts.Agencyid=Policy.Agentid
group by
Receipts.CompanyNumber1,Receipts.CompanyNumber2,
Receipts.Premium1,Receipts.Premium2,
Receipts.TransactionType,policy.Renewalofferdate,
Receipts.Agencyid



GO


Query plan...

----------------------Query Plan

|--Sort(DISTINCT ORDER BY:([Expr1008] ASC, [Expr1009] ASC, [Expr1010] ASC, [Expr1011] ASC, [Expr1012] ASC, [Expr1013] ASC, [Expr1014] ASC, [Expr1015] ASC, [Expr1016] ASC, [Expr1017] ASC, [Expr1018] ASC, [Expr1019] ASC, [Expr1020] ASC, [Expr1021] ASC, [Ex
|--Compute Scalar(DEFINE:([Expr1008]=Convert([Receipts].[CompanyNumber1])+Convert([Receipts].[CompanyNumber2]), [Expr1009]=[Receipts].[Premium1]+[Receipts].[Premium2], [Expr1010]=If ([Receipts].[TransactionType]='CAN') then ([Receipts].[Premium1]+[R
|--Compute Scalar(DEFINE:([Expr1004]=Convert([Expr1076]), [Expr1005]=Convert([Expr1077]), [Expr1006]=Convert([Expr1078]), [Expr1007]=If ([Expr1078]=0) then NULL else [Expr1079]))
|--Stream Aggregate(GROUP BY:([Receipts].[CompanyNumber1], [Receipts].[CompanyNumber2], [Receipts].[Premium1], [Receipts].[Premium2], [Receipts].[TransactionType], [Policy].[RenewalOfferDate], [Receipts].[AgencyID]) DEFINE:([Expr1076]=COUN
|--Sort(ORDER BY:([Receipts].[CompanyNumber1] ASC, [Receipts].[CompanyNumber2] ASC, [Receipts].[Premium1] ASC, [Receipts].[Premium2] ASC, [Receipts].[TransactionType] ASC, [Policy].[RenewalOfferDate] ASC, [Receipts].[AgencyID] ASC))
|--Hash Match(Inner Join, HASH:([Policy].[AgentID])=([Receipts].[AgencyID]), RESIDUAL:([Policy].[AgentID]=[Receipts].[AgencyID]))
|--Table Scan(OBJECT:([gasInquiry].[dbo].[Policy]))
|--Table Scan(OBJECT:([gasInquiry].[dbo].[Receipts]))



The two tables has number of records as 13349 and 97032.It taking more than 30 mins...
Any way to make it faster...

View 14 Replies View Related

How Do I Make 30 Sec Running Query (select C1 Sum(x) From T1 Where C1 &&> 1000 Group By C1) Run Faster?

Aug 10, 2007

It seems when I run the query with the set staticts IO on then statistic reports back with the 'work table', and the query takes 30+ sec. if the worktable is ommited(whatever the reason?) the query take less 1 sec.


Here is my take, I believe work table is created in tempdb...and if not then whole query is using the cached page, am I right?

if I am right then the theory is, if I increase the (via sp_configure) server min memory setting and min query memory, the query ought use the cached page and return in less 1 sec. (specially there is absolutely no one but me on the server), so far I can't make it go faster...what setting am I missing to make it run faster?


Another question is if the query can not avoid but use the tempdb, is it going to always be 30 sec+ time? why is tempdb involvement make it go so much slower?


Thanks in for you help in advance

View 1 Replies View Related

How Can I Make It Faster?

Apr 17, 2008

I recently installed SQL2005 Express on a Dell Precision workstation to be accessed by 6 users. The PC has XP Pro, 2GB memory, and 2.0GHz core2due CPU. This PC is dedicated for the database only.
I also set XP Performance options in System Properties to Background services and System cache.
Now, the users are experiencing slow response from the database.
How can I make the database response faster?
Thanks for your input.

View 4 Replies View Related

How To Make Insert Faster

Jan 26, 2001

Hi.We have stored procedure update specific table
Each time it run it delete 5000- 6000 rows
from table then insert 5000- 6000 rows with different information.
It take up to 1 1/2 min execute.

1.Can force Sql server do not make entry for each insert and if yes would it increase speed of procedure ?
2. Is any other way increase speed of insert?

View 2 Replies View Related

Can I Make Subreport Run Faster?

Nov 29, 2007



Hi:

I have thousands of rows that I have to retrieve for my report. When I run my main report it returns my data as a reasonable time.

When I run my sub report (by its own) again data are returned in reasonable time.

When I build the sub report in my main report it takes forever (I have to stop). Are there any tricks that I can use to make this run faster?





Thank you in advance

Bahram

View 3 Replies View Related

Would Split Make It Faster ??

Aug 5, 2007

Hi,
Here is the typical processing I do in Data Flow
1) read data file (data source)
2) do something with the data (e.g. derived column, script component, etc)
3) pass data as parameters into OLE DB command (stored proc) to take care of the rest.

Would it be faster if
I split the data into say 10 "chunks" (using split transform). Each chunk will go to its own OLE DB command (10 OLE DB command). Now I will have 10 concurrent processes running the stored proc ?

Am i misunderstanding concurrent process here ?

Thanks

View 1 Replies View Related

Make Stored Proc Faster

Jun 17, 2004

Anyone got any alternatives to the SQL Statement below that would make it run a bit faster:

ALTER PROCEDURE sproc_ReturnAvailability

@ExtractDate DateTime,
@DateFrom DateTime,
@DateTo DateTime,
@96hrPlusFlag int,
@AppointmentsCount int OUTPUT

AS

IF @96hrPlusFlag = 0

BEGIN
SELECT @AppointmentsCount = COUNT(tbl_SurgerySlot.SurgerySlotKey)
FROM tbl_SurgerySlot
INNER JOIN tbl_SurgerySlotDescription ON (tbl_SurgerySlot.Label = tbl_SurgerySlotDescription.Label AND tbl_SurgerySlot.PracticeCode = tbl_SurgerySlotDescription.PracticeCode)
AND tbl_SurgerySlot.ExtractDate = @ExtractDate
AND tbl_SurgerySlot.StartTime BETWEEN @DateFrom AND @DateTo
AND tbl_SurgerySlotDescription.NormalBookable = 1
AND tbl_SurgerySlot.SurgerySlotKey NOT IN(
SELECT tbl_Appointment.SurgerySlotKey
FROM tbl_Appointment
WHERE tbl_Appointment.ExtractDate = @ExtractDate
AND tbl_Appointment.Deleted = 0
AND tbl_Appointment.Cancelled = 0
)
END
ELSE

BEGIN
IF @96hrPlusFlag = 1

SELECT @AppointmentsCount = COUNT(tbl_SurgerySlot.SurgerySlotKey)
FROM tbl_SurgerySlot
INNER JOIN tbl_SurgerySlotDescription ON (tbl_SurgerySlot.Label = tbl_SurgerySlotDescription.Label AND tbl_SurgerySlot.PracticeCode = tbl_SurgerySlotDescription.PracticeCode)
AND tbl_SurgerySlot.ExtractDate = @ExtractDate
AND tbl_SurgerySlot.StartTime >@DateTo
AND tbl_SurgerySlotDescription.NormalBookable = 1
AND tbl_SurgerySlot.SurgerySlotKey NOT IN(
SELECT tbl_Appointment.SurgerySlotKey
FROM tbl_Appointment
WHERE tbl_Appointment.ExtractDate = @ExtractDate
AND tbl_Appointment.Deleted = 0
AND tbl_Appointment.Cancelled = 0
)

END

Cheers...

View 1 Replies View Related

How To Make You Reports Load Faster ?

Sep 3, 2007

Any ideas how to make reports faster when returning lots fo rows?
I know you would need to work on your sql query etc..
Or maybe cache it.
But i'm thinking of having a kind of middle tier thing that sits between your sql database and the reports itself.
Any ideas would be appreciated

View 2 Replies View Related

Indexing SL CE To Make Search Faster. How?

Jan 11, 2006

Dear VB coders!

I have 8.000 or 16.000 products on my list in an sql table. It takes 8 or 16 secs to find the last item.

How could I make the search faster? Indexing? But how?

I created:
createTable1.CommandText = "Create TABLE products (ID int IDENTITY(0,1) PRIMARY KEY, name ntext)"
 
and I use simple WHERE to search.
 
Thank you!

View 3 Replies View Related

I Need A Faster Query

Jun 20, 2007

Hi y'all,
I've recently run a profiler on my code and following query took 7 seconds:
SELECT TOP 10 UI, COUNT(UI) AS Expr1 FROM table WHERE (UI <> 'custom_welcome') GROUP BY UI ORDER BY COUNT(UI) DESC
Is it possible to rewrite this so my code gets faster? It's also possible that it's due to the size of the table?
Thanks in advance! I'll let you know how long your query takes :)

View 4 Replies View Related

Faster SQL Query

Mar 31, 2004

Hi!
I M basically an application developer & use simple sql queries in my programmings. I do not have much idea abt tuning/auditing part & thatswhy i m unable to answer them properly in my interviews. Can anybody give me some tips?????

Question 1:
In a stored procedure, One SELECT stmt is there & depending upon the @rowcount, it updates around 14000 records which is also written inside this stored procedure. Instead of writing this way, there is some other way which is faster than this. Can anybody tell me the correct way???

Question 2:Can anybody give me few examples like this?????? I need them desparetly.

Thanx. Bye.

View 37 Replies View Related

How To Tell If One Query Is Faster Than Another

Jul 26, 2006

I have rewritten a stored procedure that consists of a single select that selects from a view. Essentially I combined the select in the view and the select in the sp into one select. I am now trying to determine if the new version is faster.

The estimated execution plan gives a ratio of 96% : 4% in favour of the new version when I run them together from a query window but when I try to time them I can't get a satisfactory result.

If I run each query once and display the difference between start and end time, they display 0. If I run each one 100, 200, etc times I get different results each time.

Is there anything I can do?

View 5 Replies View Related

Faster Query Results

Oct 17, 2007

Can anyone give me the basics of speeding up reports that use queries or views or nested views?
Current reports are now taking over 2 minutes to show.We have thousands and sometimes even millions of records to report against.Queries have 4 and 5 table joins etc.
We are using ASP.NET 2.0 in Visual Studio 2005 and Crystal Reports.
Thanks
 

View 4 Replies View Related

Query Run Time (which Should Be Faster?)

Feb 28, 2008

Hi, when I execute the sql in DBTestArchive and then DBTest query analyzer , I found that the run time is shorter in DBTest. Can I make assumption that the query run time is shorter in DBTest if I select data from it and insert into another database? Thanks.



INSERT INTO DBTestArchive.dbo.tblVendorMasterArchive
SELECT * FROM DBTest.dbo.tblVendorMaster

View 1 Replies View Related

Better (faster) Way Of Handling Query

Mar 26, 2008



I have a query which will display the employee name who is handling maximum number of project.
the query is



Code Snippet

select EmployeeDetails.Empid,

EmployeeDetails.FirstName + ' '+EmployeeDetails.LastName as EmpName,

count(*) as Number_Of_Projects
from EmployeeDetails left outer join LUP_EmpProject

on EmployeeDetails.Empid= LUP_EmpProject.Empid
group by EmployeeDetails.Empid,EmployeeDetails.FirstName,EmployeeDetails.LastName
HAVING count(*)=(SELECT TOP 1 COUNT(EmpID)



FROM LUP_EmpProject GROUP BY EmpID ORDER BY 1 DESC)






where EmployeeDetails table contain empname and empid. LUP_EmpProject table contain empid and project id.

Can anybody help me in writing a better query than the above given?

Please help!!!!!!!!!!

View 4 Replies View Related

Drop PK And Query Runs Faster. Why?

Aug 23, 2000

I have a query which joins multiple tables. This query has suddenly begun to take up to 2 minutes to run (vs. 5-10 seconds previously).

No major change in number of records in the tables (currently about 220,000). When I remove the PK from one of the tables which then forces a tablescan, the query returns to running in 5-10 seconds. If I add the PK back, performance is back to 2 minutes.

Any suggestions short and/or long term?

Thanks for any help.

View 1 Replies View Related

AdHoc Query Faster Than Stored Proc?

Aug 28, 2004

Yesterday i face a strange SQL Server 2000 behaviour :-(

I had a query that was wrapped inside a stored procedure, as usual.
Suddenly, the stored procedure execution time raised from 9 secs to 80.

So to understand where the problem was i cut and pasted the sp body's into a new query analyzer window an then executed it again. Speed back to 9 secs.
Tried stored procedure again, and speed again set to 80 secs.

Tried to recompile sp. Nothing. Tried to restart SQL Server. Nothing. Tried to DROP & RE-CREATE sp. Done! Speed again at 9 secs.

My collegue asked me "why?", but i had no words. :confused: Do you have any explanation?

View 5 Replies View Related

Why Is DTS Faster Than A Query To Load A Remote Table?

Apr 23, 2007

Hello

DTS is notoriously faster than making the following statement:

insert into synonym_MyRemoteTable
select * from myLocalTable

Why is it so?

Thanks a lot.

View 6 Replies View Related

Faster Query - Select By One Or Multiple Fields

Feb 1, 2008

Let's say I have a table of users.
Let's imagine there's two fields:
username (PK),
password

Now I need to authenticate a user against this table. What is the recommended approach? Is it better / faster to
(1) SELECT * FROM [User]
WHERE username = 'whatever' AND password='whatever'
or
(2) SELECT * FROM [User]
WHERE username = 'whatever'
and then in my code check that the record returned matched the password?

View 6 Replies View Related

Why Does A Query Runs Considerably Faster Than Stored Procedure?

Dec 29, 2003

I have an stored procedure that takes 23 seconds to execute. However, the same query is executed in 4 seconds.

All the tests where made using the Query Analizer.

What could be wrong?

Thanks a lot in advance.

View 13 Replies View Related

Same Statement Executes 10 Times Faster As Raw Sql In Query Analyzer Then In A Stored Proc

Aug 15, 2007



Hi,


I apologize for the long post but I am trying to give as much information as I can about the steps I've taken to troubleshoot this.


We have a stored procedure that builds a sql statement and executes it using the Execute command. When I execute the stored procedure through query analyzer it takes close to 5 seconds to execute. When I print out the exact same statement and execute it directly in query analyzer as "raw sql", it takes 0.5 seconds - meaning it takes 10 times longer for the code to execute in the stored proc. I altered the stored proc to execute the printed sql instead of building but it still takes the full 5 seconds and there were no changes in the execution plan. This makes me confident that the issue is not caused by the dynamic sql. I've used with recompile to make sure that the stored procedure caches the most recent execution plan. When I compare the execution plans, the stored proc uses a nested loop whereas the raw sql statement uses a hash join. Seeing that, I added the hash hint to the stored proc and doing so brought down the execution time down from 5 secs to 2 secs but still the raw sql statement uses a clustered index whereas the stored proc uses a non-clustered index and that makes the statement 4 times slower. This proves how efficient clustered indexes are over non-clustered ones, but it doesn't help me since, as far as I know, I can't force SQL Server to use the clustered index.


Does anyone know why sql server is generating such an inefficient execution plan for the stored proc compared to the execution plan that it generates when executing the raw sql statement? The only thing I can think of is that some stats are not updated and that somehow throws off the stored proc. But then again, shouldn't it affect the raw sql statement?


Thank you,


Michael Tzoanos

View 4 Replies View Related

How To Create A Make-Table Query With A Union Query

Oct 30, 2006

I have successfully execute a union query. How can i create a make-table query to accomodate the resultset of the union query?

View 2 Replies View Related

Query Executes Faster In Grid Mode Than In Text Mode!!

Mar 9, 2000

Hello,everyone!!

There is a query which when executed in the grid mode(ctrl+d) takes approx 0.02 seconds(about 21,000
rows) But when I execute in the text mode, it takes about 0.40 seconds!!
Why is this difference?
Also, when the records from this table are read from a VB application, they are equally slow (as in the text mode!)
Why is it so slow on the text mode & relatively faster in the grid mode?
Has anyone got any idea on ‘Firehose’ style cursor ?(which may speed up access of data in the VB application)

Rgds,
Adie

View 1 Replies View Related

Need To Make This Query

Jun 28, 2004

Hi guys, I have a car_race table which has these fields

car_id int
race_id int
b_car_won varchar // can have 'y' or 'n'

I need to know if the car lost the 1st race but won the next race

And example of that table for car_id 1:

car_id 1
race_id 1
b_car_won 'NO'

car_id 1
race_id 2
b_car_won 'YES'

Now this is the tricky part, the database has some data integrity issues, so this can occur:

car_id 1
race_id 1
b_car_won 'NO'

car_id 1
race_id 3
b_car_won 'YES'

So I cant used a fixed race_id value, need to use the race_id > 1 to know whats the next race. But this raises another issue if I have this in the database:

car_id 1
race_id 1
b_car_won 'NO'

car_id 1
race_id 3
b_car_won 'YES'

car_id 1
race_id 4
b_car_won 'YES'

If I query I'd get 2 rows where race_id > 1. And I only need the first one, because 3 is the next race.

I need to fetch in a single row if possible, the result of the 1st race and the 2nd race. How can I do this?

View 11 Replies View Related

How To Make Query Look Better

Aug 28, 2007

select contractnbr,affcontractnbr,tdd,affrtramount,affturn,
pt=datediff(d,afffirstfundingdate,affRTRBalanceZeroDate),ratio=datediff(d,afffirstfundingdate,affRTRBalanceZeroDate)/afftrun
from #targetfinishedaff

datediff(d,afffirstfundingdate,affRTRBalanceZeroDate) appears two times in this code, Is there a way to make it appear only once?
Thx

View 1 Replies View Related

How To Make This Query?

Feb 14, 2008

I want to make query for average sales price, the records are like this

item, Sales_qty, UnitPrice
A, 10, 1000
A, 20, 1100
A, 5, 1500
B, 1, 1000
B, 2, 1200

and display like this
A, 35, 1128 (35 FROM total qty, 1128 from average sales price)
B, 3, 1133

Thanks in advance

View 8 Replies View Related

Make Two Query In Too One

Jul 20, 2005

I have two SQL query that I would like to make in to one, if possibleHere is the first one: (Query4)SELECT rooms.DESCRIPTIO, rooms.ID, bookings1.DATEFROM bookings1 INNER JOIN rooms ON bookings1.ROOMID = rooms.IDWHERE (((bookings1.DATE) Between #4/3/2004# And #4/9/2004#));And the second one:SELECT rooms.ID, rooms.DESCRIPTIO, Query4.ROOMIDFROM rooms LEFT JOIN Query4 ON rooms.ID = Query4.ROOMIDWHERE (((Query4.ROOMID) Is Null));Is it possible to make one query of this two?With the same result.

View 3 Replies View Related

How Can I Make Such Query?

Jan 9, 2008

I havea textbox for searching by patient name but now and though I am searching with LIKE% i can only search for exact string, for example if user typed JASSIM it will search for field full_name LIKE '%JASSIM%" ad if user typed JASSIM RAHMA it will search for full_name LIKE '%JASSIM RAHMA%' but i want to search if the field CONTAINS '%JASSIM% AND %RAHMA% when the user types JASSIM RAHAM in the textbox

View 4 Replies View Related

How To Make This Query...

Sep 16, 2007




Hi all. I have tried making this query for a while and i didn't manage to.
I know it is something related to JOIN, but i didn't manage to make it work :
I have two tables.
Table1- db_stockprices
Table2- db_stockSymbols

db_stockprices is getting updated every day with stock daily prices.
db_stockprices looks like:
ID, SymbolID, Price,Date
1 1 33.21 1/1/2007
2 1 33.14 1/2/2007
3 1 34.21 1/3/2007
4 2 11.42 1/1/2007
5 2 11.73 1/2/2007
6 3 18.32 1/1/2007
7 3 19.11 1/2/2007
8 3 18.41 1/3/2007
9 4 52.44 1/1/2007

and so on for all the stocks.
ID is Primary Key
SymbolID is related to SymbolID in db_stockSymbols which contains all the stock information.

What i am trying to do is an SQL QUERY that will delete all same SymbolID Rows if a specific INPUT date do not exist within that SymbolID.

Example:
If the INPUT date for the query is 1/3/2007 all rows with SymbolID "2" abd "4" will be deleted since 1/3/2007 does not exist in SymbolID "2" and "4". Moreover, the row in db_stockSymbols with SymbolID "2" and "4" will also be deleted.


Is this possible within 1 SQL Query?
I would really appreciate a good query example for this example..

View 13 Replies View Related

Need Help To Make Query

May 11, 2006

Dear member

Hi

I have a problem,

I have a table for my company name and another for cities.

I have a table Company_City to indicate that each company has office in each city

For example

company X in city A company Y in city B

company X in city B company Y in city H

company X in city C

I want make a query to retrieve companies that have office in city A and B. so company Y that has office in B only should not retrieved in my query.

If i use "IN" operator(by subquery from city table) in my WHERE Clouse the result will be A,B.

Can you help me?

View 4 Replies View Related

How To Make The SSMSE To Return Whole Records Without Any Close Query Form And Re-create Query Form Operation?

Dec 25, 2007

Hi,
I got a problem.
I installed Microsoft SQL Server Management Studio Express 2005 version.
And I created a Compact database.
I created an connection in SSMSE to connect the database and opened a query form.
then, i run the following sql:

Select * from Table1

It returned 3 records to me.
After that, I used program to insert record into this table.
Then i ran this sql again, it still show me 3 records.
I closed the query form, and re-created a new query form, then run the sql, it returned 4 records to me.

Why? It's very strange and difficult to operate, right?
Is there anyone know how to make the SSMSE to return whole records without any close query form and re-create query form operation?

Thanks a lot!

And Merry X'max!!!

View 4 Replies View Related

Can't Seem To Make This Query Work

Jul 24, 2006

Hi,
I have a query thatI need to make into one query for the sake of an application reading only one cursor.
 
Here's the syntax:
select (select distinct(x.amount) from escrow k inner join e120 x on k.escrow = x.escrowinner join a10 g on x.escrow = g.escrow  where k.ftype = 'S' group by x.amount, g.officer) As New,a.officer as Officer, count(distinct(j.fstatus))as Escrow_Type, count(distinct(j.amount))as Amount, count(distinct(d.open_date))as [Open], count(distinct(d.close_date)) as Closed, count(distinct(can_date))as Cancelled
from a10 a inner join escrow d on a.escrow = d.escrowinner join e120 j on j.escrow = d.escrow where j.id_scr = 'e21' and j.fstatus = 'PAID' group by a.officer
 
The error message i'm recieving is the following:
 
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
 
Any ideas? any suggestions would be great.
 
Thanks

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved