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)
 Left function in Where clause slow down

Author  Topic 

Naumaan
Starting Member

2 Posts

Posted - 2006-09-28 : 13:53:23
I have used Left function in where clause and it slow down data fetching extremely.But if i did not use left function then same query fetch data in few seconds. Can anybody helps me in this matter. eg where (left(AccountNumber,4) = @Accountnumber).

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-28 : 13:59:27
Because it can't use the index as it needs to perform an operation on all the columns.
try
where AccountNumber like @Accountnumber + '%'
if @Accountnumber is 4 characters.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Naumaan
Starting Member

2 Posts

Posted - 2006-09-28 : 15:13:00
Thanks for the help, I have another question . if i join tables like

left join
(

select left(AccountNumber,4) AccNum,
..............
..............
..............

)c on left(a.AccountNumber,4) = c.AccNum
then can i use like insted of left while joining tables. if yes then plz give me some example.
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2006-09-29 : 04:03:24
Yes you can - and it is the same syntax as the WHERE clause.
Go to Top of Page
   

- Advertisement -