SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Ltrim + Like
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwacz23
Starting Member

44 Posts

Posted - 08/14/2013 :  03:15:31  Show Profile  Reply with Quote
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

Sweden
30188 Posts

Posted - 08/14/2013 :  03:46:08  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 08/14/2013 :  03:52:41  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2206 Posts

Posted - 08/14/2013 :  03:59:14  Show Profile  Reply with Quote
REPLACE(response, ' ', '')

--
Chandu
Go to Top of Page

kwacz23
Starting Member

44 Posts

Posted - 08/14/2013 :  04:03:25  Show Profile  Reply with Quote
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

Sweden
30188 Posts

Posted - 08/14/2013 :  06:51:05  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT	LTRIM(RTRIM(Question)) AS AttributeName,
	LTRIM(RTRIM(Response)) AS Value
FROM	dbo.SC_RequestQuestionData
WHERE	Request_Data_ID = 11046
	AND Question LIKE '%_ATT';



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

bandi
Flowing Fount of Yak Knowledge

India
2206 Posts

Posted - 08/14/2013 :  08:01:22  Show Profile  Reply with Quote
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

India
20 Posts

Posted - 08/28/2013 :  09:49:58  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000