Hello!
I have a query with multiple table joints and where clauses. Tables are huge and query runs for a very long time. I need to run another query, which is exactly the same apart for one Where clause (first time price = "P", second time price = "S"). I use this for BIRT report, which means I need to have a result of there two queries at the same time. I can run them at the same time, but because they are both huge it takes a Long time. I wonder if I can make only one query, will it be faster? And if it will- what’s the best way to make it?
Thank you for your help!
Please let me know if it is not clear.
Roughly my code:
Select * FROM sales_item d
join (select str_to_date('2007-09-30', '%Y-%m-%d') st_date) v
join item_store f on f.item_no=d.item_no and f.store_id = d.store_id
join item_sellprice_store a on f.item_no=a.item_no and f.store_id = a.store_id
join item b on f.item_no=b.item_no
join item_supplier c on b.item_no=c.item_no and b.supplier_no=c.supplier_no
join item_sellprice_storegroup g on a.batch_id=g.batch_id
join store k on f.store_id =k.store_id
where d.store_id = '011'
and (f.item_status ='A' or f.item_status ='O')
and a.price_type='P'
and a.effective_start_date < v.st_date < a.effective_end_date
and d.sale_date = v.st_date
order by d.category_code, a.sell_gst, a.item_no ;
And the second one is exactly the same apart from highlighted line (it’s a.price_type='S')
Hi I am pretty new to database. I want to know the difference between the 2 queries given below
1>SELECT B.col4, A.col4 , A.col5, C.col5 from tbltpcheckout A with (nolock) inner join tblTPEFTPayPal B with (nolock) on A.col1 = B.col1 inner join tbltpuser C with (nolock) on A.col3 = C.col3 where A.col2 = CONTP_CHECKOUT_STATUS_PENDING
2>SELECT B.col4, A.col4 , A.col5, C.col5 from tbltpcheckout A with (nolock) , tblTPEFTPayPal B with (nolock), tbltpuser C with (nolock) where A.col1 = B.col1 and A.col3 = B.col3 and A.col2 = CONTP_CHECKOUT_STATUS_PENDING
If any one can help me in understanding the difference
Is there any difference between the two queries given below..I am not able to find any but am not sure. Kindly help.
A)
select a.* from( select top 1 hs.last_modified, hs.price, hs.revision_date from history hs where hs.last_modified < '06-Jan-2008' order by hs.last_modified desc)a order by a.revision_date desc
B) select hs.last_modified, hs.price, hs.revision_date from history hs where hs.last_modified < '06-Jan-2008' order by hs.last_modified desc, hs.revision_date desc
HelloWhen I use a PreparedStatement (in jdbc) with the following query:SELECT store_groups_idFROM store_groupsWHERE store_groups_id IS NOT NULLAND type = ?ORDER BY group_nameIt takes a significantly longer time to run (the time it takes forexecuteQuery() to return ) than if I useSELECT store_groups_idFROM store_groupsWHERE store_groups_id IS NOT NULLAND type = 'M'ORDER BY group_nameAfter tracing the problem down, it appears that this is not preciselya java issue, but rather has to do with the underlying cost of runningparameterized queries.When I open up MS Enterprise Manager and type the same query in - italso takes far longer for the parameterized query to run when I usethe version of the query with bind (?) parameters.This only happens when the table in question is large - I am seeingthis behaviour for a table with > 1,000,000 records. It doesn't makesense to me why a parameterized query would run SLOWER than acompletely ad-hoc query when it is supposed to be more efficient.Furthermore, if one were to say that the reason for this behaviour isthat the query is first getting compliled and then the parameters aregetting sent over - thus resulting in a longer percieved executiontime - I would respond that if this were the case then A) it shouldn'tbe any different if it were run against a large or small table B) thisperformance hit should only be experienced the first time that thequery is run C) the performance hit should only be 2x the time for thenon-parameterized query takes to run - the difference in response timeis more like 4-10 times the time it takes for the non parameterizedversion to run!!!Is this a sql-server specific problem or something that would pertainto other databases as well? I there something about the coorect use ofbind parameters that I overall don't understand?If I can provide some hints in Java then this would be great..otherwise, do I need to turn/off certain settings on the databaseitself?If nothing else works, I will have to either find or write a wrapperaround the Statement object that acts like a prepared statement but inreality sends regular Statement objects to the JDBC driver. I wouldthen put some inteligence in the database layer for deciding whetherto use this special -hack- object or a regular prepared statementdepending on the expected overhead. (Obviously this logic would onlybe written in once place.. etc.. IoC.. ) HOWEVER, I would desperatelywant to avoid doing this.Please help :)
What is the difference between below? And how can I make GETDATE() the same as System.DateTime.Today.ToShortDateString()? System.DateTime.Today.ToShortDateString() and GETDATE()
Hello, I am transfereing Data into text format. The datas are about 5 table and has almost 50000 to 2 million rows. I am using the same query for BCP and DTS. But I find the dreference between those. I mean DTS is taking less memory and more time than BCP to complete the process . Anybody can share any comment for this issue ?.
hi, i'm having difficulty figuring out how to implement a set difference between two queries. the only set operator i've been able to come across is union. thanks in advance! d
Are SQL Server Express & SQL Server 2005 one & the same thing? Or is the former a part of the latter? Actually when I was downloading Visual Web Developer 2005 Express, I was given the option to download Microsoft SQL Server 2005 Express Edition as well; so I am getting confused between SQL Server Express & SQL Server 2005.
I installed SQL Server 2005 in my WinXP Pro m/c. from the Microsoft website (after re-installing WinXP Pro since XP became corrupt). Earlier I used to login to Management Studio Express using my m/c. name followed by a followed by SQLEXPRESS as the server name. So if my m/c. name is MyPC, then I used to login to Management Studio Express using MyPCSQLEXPRESS as the server name but now when I try to login to Management Studio Express using the above server name i.e. MyPCSQLEXPRESS, then an error gets thrown saying
Cannot connect to MyPCSQLEXPRESS.
Now how do I find out what's the server name so that I can login to create & manage databases in Management Studio Express?
Please note that after re-installing WinXP Pro, my m/c. name has remained the same; I didn't change it.
Hi, I want to know what are the differencve between CONTAINS and LIKE, Which is better to use and in which condition.???? I searched on google but can't able to find out major differnces or any good article realted to this,
I have two numeric variables in T-SQL - @Var1 and @Var2These variables can be positive or negative. I want to find the difference between the two variables, eg:@Var1 = -50@Var2 = 25Difference = 25 @Var1 = -50@Var2 = -40Difference = 10 @Var1 = 60@Var2 = 10Difference = 50 Is there a function in SQL Server to carry this out?
It may be sound weird. I want to find the difference between SQL Stored procedure and functions. I knew a couple one is for function, parameter is must where as in SP its not, second is function would return a value whereas procedure wont.
I want to create a View, which contains columns from two tables, and an additional column, which should calculate the difference between two dates.01/05/2005 7:30 AM - 01/05/2005 8:00 AMThe column should be a calculated column,Can I assign the value of a column to a user defined function?In the UDF, how to get the difference between those two dates to be: "00:30"Are there SQL Server functions to time and date that allows me to do so? I have dateadd, datediff, but I am unable to figure out the 2 problems above.thank you,
In my table i have two cols and datatype datetime, for example they has the values,--------StartDate --------------------------------------- StopDate ------______________________________________________01/05/2005 7:30 AM ------------------------ 03/05/2005 10:00 AM13/05/2005 2:30 PM ------------------------- 01/08/2005 8:00 PM_____________________________________________How do I find out the avg time difference between StopDate and StartDate? I tried AVG(StopDate - StartDate ), but it's giving me the following error message. "The average aggregate operation cannot take a smalldatetime data type as an argument."Thanks for any reply.
I have a view in a database called PS_EMPLMT_SRCH_US and it joins around five tables. I have two databases which are identical structures including data. But when run one query ie "SELECT * FROM PS_EMPLMT_SRCH_US where EMPLID like '00918%' and OPRCLASS like 'ALLPANLS' ", response time is totally different even though both databases have same data and same indexes. When I looked at showplan and stats time, both are totally different and order of table fetch is totally different. Is there any idea why this difference? Any help would be appreciated.
Here is the show plan info: ------------------------------------------------------------------- GOOD Performance Query and plan -------------------------------------------------------------------
SELECT * FROM PS_EMPLMT_SRCH_US where EMPLID like '00918%' and OPRCLASS like 'ALLPANLS'
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. SQL Server parse and compile time: CPU time = 156 ms, elapsed time = 156 ms.
Hi I wanted to get difference between this two dates '12-31-2001','01-01-2002'). 1 day 0 month 0 year. Do we have any date function to get like this or we need write our own function stored proc?> Any advice please?.
Hi , I need logic for find the month diffrence. For example '08/05/2003','10/01/2003' I should get difference between these two date is 1. Thanks, Ravi