Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Query Tuning

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-03-20 : 09:47:58
Vijay writes "I have a query (pasted below) that has to be tuned. Right now, the non-clustered indexes defined on columns in the where clause are not used (because of concatenation).

Kindly let me know the best way to tune this statement.

select Compshrtdescr,Unitshrtdescr,AccCd_FK,AccCdShrtDescr,
@balmnth as Balmnth,Closebal as OpBal,
0.00,0.00,0.00 from Ggac_Accmonthbal
where Compshrtdescr=@p_CompShrtDescr
and Unitshrtdescr =@p_UnitShrtDescr and
ltrim(rtrim(Compshrtdescr))+ltrim(rtrim(Unitshrtdescr))+
ltrim(rtrim(AccCdShrtDescr))+ltrim(rtrim(Balmnth))
in (select ltrim(rtrim(Compshrtdescr))+ltrim(rtrim(Unitshrtdescr))+
ltrim(rtrim(AccCdShrtDescr))+ltrim(rtrim(max(balmnth)))from ggac_accmonthbal
where Balmnth < @Balmnth and Compshrtdescr=@p_CompShrtDescr and
Unitshrtdescr =@p_UnitShrtDescr and ltrim(rtrim(Compshrtdescr))+
ltrim(rtrim(Unitshrtdescr))+ltrim(rtrim(AccCdShrtDescr))
in (select ltrim(rtrim(Compshrtdescr))+ltrim(rtrim(Unitshrtdescr))+
ltrim(rtrim(AccCdShrtDescr)) from #TranDet)
group by Compshrtdescr,Unitshrtdescr,AccCd_fk,AccCdShrtDescr)

Thanks in advance.

Regards,
Vijay."

rlaubert
Yak Posting Veteran

96 Posts

Posted - 2007-03-20 : 13:06:12
What are the table definitions for #TransDet and Ggac_Accmonthbal


Raymond Laubert
MCDBA, MCITP:Administration, MCT
Go to Top of Page
   

- Advertisement -