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 2008 Forums
 Transact-SQL (2008)
 Ltrim + Like

Author  Topic 

kwacz23
Starting Member

44 Posts

Posted - 2013-08-14 : 03:15:31
Hi

How I can use function ltrim with Like? last line is not working

SELECT question [AttributeName],response [Value]
FROM SC_RequestQuestionData
WHERE request_data_id =11029
AND ltrim(question LIKE '%_ATT')

Could you help?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-14 : 03:46:08
There is no need to LTRIM your column when your criteria starts with a wildcard.
What you want is to get all rows where the column Question ends with "ATT".

AND Question LIKE '%_ATT'

will be enough. If you insist in using LTRIM, this is how it should look like

AND LTRIM(Question) LIKE '%_ATT'



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

kwacz23
Starting Member

44 Posts

Posted - 2013-08-14 : 03:52:41
Thanks for help.

However I would like to display results for 'respone' without extra spaces. I am using that but is not help. In this column value are with spaces, I would like to transfer value without this space

SELECT question [AttributeName],ltrim(rtrim(response))Value
FROM SC_RequestQuestionData
WHERE request_data_id = 11046
AND question LIKE '%_ATT'
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-14 : 03:59:14
REPLACE(response, ' ', '')

--
Chandu
Go to Top of Page

kwacz23
Starting Member

44 Posts

Posted - 2013-08-14 : 04:03:25
Chandu thanks for you hint, but I would like to only romve first space on the left side if exist.

Example

' Win 7 32bit'- here only remove this first extra space.
'Win 7 32bit'- here should be as it is now
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-14 : 06:51:05
[code]SELECT LTRIM(RTRIM(Question)) AS AttributeName,
LTRIM(RTRIM(Response)) AS Value
FROM dbo.SC_RequestQuestionData
WHERE Request_Data_ID = 11046
AND Question LIKE '%_ATT';[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-14 : 08:01:22
quote:
Originally posted by kwacz23

Chandu thanks for you hint, but I would like to only romve first space on the left side if exist.

Example

' Win 7 32bit'- here only remove this first extra space.
'Win 7 32bit'- here should be as it is now


SELECT LTRIM(' Win 7 32bit') RemoveLeftSpace
SELECT RTRIM('Win 7 32bit ') RemoveRightSpace
SELECT LTRIM(RTRIM(' Win 7 32bit ')) RemoveBothSpaces

--
Chandu
Go to Top of Page

ShivaKrishna
Starting Member

20 Posts

Posted - 2013-08-28 : 09:49:58
SELECT LTRIM(RTRIM(Question)) AS AttributeName,
LTRIM(RTRIM(Response)) AS Value
FROM dbo.SC_RequestQuestionData
WHERE Request_Data_ID = 11046
AND Question LIKE '%_ATT'
Go to Top of Page
   

- Advertisement -