Dear Friends,
I am stuck up with Database Query Performance once again..
One Select Query - is taking a lot of time to execute - 7minutes for 30records.
Query -
select distinct incoming.IC_NO,
(case when ISNUMERIC(incoming.IC_RECEIVERS_SR_ID) <> 1 then incoming.IC_RECEIVERS_SR_ID when ISNUMERIC(incoming.IC_RECEIVERS_SR_ID) = 1
then (select sr.SR_NAME from SENDERRECEIVER sr where sr.SR_ID = cast( incoming.IC_RECEIVERS_SR_ID as numeric) )end) as 'IC_RECEIVERS_SR_ID',
(select courier.CSP_NAME from COURIERSERVICEPROVIDER courier where courier.CSP_ID = incoming.IC_CSP_ID) as 'Courier Service Name',
equip.EQ_DESC as 'Site',
(select REPLACE(t.EQ_DESC,'–','') from EQUIPMENT t where t.EQ_L1 = equip.eq_code and t.EQ_LEVEL = 2 and incoming.IC_SUBHUBLOC = t.EQ_CODE) as 'Subhurb',
incoming.IC_WEIGHT, incoming.IC_RATE , incoming.IC_CONSIGNMENTRECDATETIME,
incoming.IC_ReceiverCity as 'Receiver City',
incoming.IC_RECEIVERPINCODE as 'Receiver Pincode',
incoming.IC_AIRWAYBILLNO as 'Airway Bill No',
incoming.IC_AMOUNT as 'Amount', incoming.IC_CREATEDBY as 'Created By',
incoming.IC_COURIERTYPE as 'Courier Type'
from INCOMINGCONSIGNMENT incoming , equipment equip,
equipment subhurb where 1=1 and IC_CONSIGNMENTRECDATETIME between '03 Jul 2017' and '03 Jul 2017'
Please guide ..
Loading
Ramesh SinghPosted Jul 18, 2017, 10:17 AM
Riddhi ValechaPosted Jul 5, 2017, 1:34 AM
Hello all..
Thank you so much ... but to be frank, I am a bit weak in Join Queries...
then (select sr.SR_NAME from SENDERRECEIVER sr where sr.SR_ID = cast( incoming.IC_RECEIVERS_SR_ID as numeric) )end) as 'IC_RECEIVERS_SR_ID', - Column - IC_RECEIVERS_SR_ID has numeric values and string values. Requirement - Where the value is a number (2,4,3, etc), then check in table SenderReceiver and take name from that table where ID = 2,3,4 - Hence I used ISNUMERIC Method.
Client processing time 31 31.0000
Total execution time 291301 291301.0000
Wait time on server replies 291270 291270.0000
Puneet KankarPosted Jul 4, 2017, 7:43 AM
Akshay PhadkePosted Jul 4, 2017, 7:19 AM
Abhilash J APosted Jul 4, 2017, 5:12 AM
if sqlserver, include actual Execution plan and estimated execution plan - if any index missing, sql server will display command to create missing index
case and cast really needed ? should be done in client (c#, vb ...) database is for retrieving data, not for calcing
subquery maybe slower then joining