Hi Friends,
Today i am facing some problem regarding sql query define below.
select at.*,currencytbl.currency,am.account_name,(case when at.isauthorized is null then 'not approved' else 'approved' end) as [status]
,(um.First_Name + ' ' + um.Last_Name) as username from account_transaction AT inner join
(select c.currency,c.id from currency c inner join currency_master cm on c.id=cm.currency_shortname) as currencytbl
on at.currencyid= currencytbl.id
inner join account_master AM on AM.account_id=at.accountid inner join USERS_DETAIL ud on am.Account_Code = ud.UserFCStockAccNo
inner join USERS_MASTER um on ud.User_Id = um.User_Id
where AT.dno in(select dno from account_transaction where transtypeid=11and creditdebit='D')
and AT.creditdebit='C' and AT.currencyid != 62
and (CAST(CreatedOn AS DATE) >= CAST('07/17/2017' AS DATE) AND CAST(CreatedOn AS DATE) <= CAST('07/17/2017' AS DATE))
this query work fine when we does not take any date field column then it executes fine with in 1 sec but when we add date column
with casting then it takes very long time to execute.
Plz Resolve.
Tapan PatelPosted Oct 11, 2017, 2:44 PM
Think like this, on each row, it tries converting date column to DATE type twice for CreatedOn and two more times for static date( 07/17/2017). It really depends on the number of rows in your table (i.e. how bad it can screw up your query)
Your current approach is correct with temp tables but you can also do something like below. I have created just a subquery to include date field as DATE and later filter based on two date variables.
Nilesh PatelPosted Oct 5, 2017, 1:55 PM
Guest UserPosted Sep 14, 2017, 10:36 PM
Nitin SontakkePosted Jul 19, 2017, 5:57 AM
Manish KumarPosted Jul 19, 2017, 4:13 AM
amit shuklaPosted Jul 18, 2017, 2:09 AM
amit shuklaPosted Jul 17, 2017, 1:17 PM
Puneet KankarPosted Jul 17, 2017, 10:06 AM