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.
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 |
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2010-10-04 : 16:42:02
|
Thanks tkizer.Is there any alternative query for Rtrim function. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
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 planIF OBJECT_ID('tempDb..#foo') IS NOT NULL DROP TABLE #fooCREATE 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 aSELECT [value]FROM #fooWHERE [value] LIKE 'a%'SELECT [value]FROM #fooWHERE RTRIM([value]) LIKE 'a%' Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
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 definedMadhivananFailing to plan is Planning to fail |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
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 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|
|