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 2005 Forums
 Transact-SQL (2005)
 TRIM

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-10-04 : 16:18:40
Does trim function usage in query will deteriorate the performance of the query.
Is there any alternate query like the trim.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-04 : 16:21:47
It will not degrade performance.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2010-10-04 : 16:42:02
Thanks tkizer.

Is there any alternative query for Rtrim function.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-04 : 17:11:56
Why do you need an alternative?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-05 : 05:20:37
Huh? It can certainly degrade performance depending on where it's used.

If you use it over a column in the where clause then you'll be unable to use an index on that column.

You should show us the query you are using.

Here's an example where it makes a difference to the query plan


IF OBJECT_ID('tempDb..#foo') IS NOT NULL DROP TABLE #foo
CREATE TABLE #foo (
[value] VARCHAR(342)
)

CREATE CLUSTERED INDEX valFoo ON #foo ([value])

INSERT #foo ([value])
SELECT
dt.[value]
FROM
(
SELECT 'a' AS [value]
UNION SELECT 'b'
UNION SELECT 'c'
UNION SELECT 'd'
UNION SELECT 'easdasd '
UNION SELECT 'asdfasf '
UNION SELECT 'asda3 4231 22 '
UNION SELECT '2 22'
)
AS dt

CROSS JOIN sys.columns AS a

SELECT
[value]
FROM
#foo
WHERE
[value] LIKE 'a%'

SELECT
[value]
FROM
#foo
WHERE
RTRIM([value]) LIKE 'a%'


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-10-05 : 06:46:52
quote:
Originally posted by sqlfresher2k7

Does trim function usage in query will deteriorate the performance of the query.
Is there any alternate query like the trim.


SQL Server has ltrim and rtrim and not trim. As said, if used in WHERE clause, they may be performance degrade if index is defined

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-05 : 11:17:13
Well of course in the WHERE clause, but how often is it used there? Any functions in there WHERE clause will degrade performance.

My comment is referring to when it is used in the SELECT portion of the query, which is most typical.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-05 : 11:42:38
quote:
Originally posted by tkizer

Well of course in the WHERE clause, but how often is it used there? Any functions in there WHERE clause will degrade performance.


......
Sorry -- Didn't mean to offend, but I've stopped taking such things for granted. When someone asks -- can this hurt then I always think "wait a minute -- what could the *possibly* be doing that would prompt them to ask the question....."

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -