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
 General SQL Server Forums
 New to SQL Server Programming
 How to check if the Word in String in Sql
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ryoka012
Starting Member

Philippines
20 Posts

Posted - 08/16/2013 :  00:21:26  Show Profile  Reply with Quote
Hi,

I have a scenario which i must check if the value of the inputted word is exact(case sensitive) in a string.And print the word if correct.

using a user defined function.

Example:The quick brown fox jump over the lazy dog.

If the user enter "jump" it must print "jump".
If the user enter "Jump" it must print "jump" which is the correct word.


Thanks.

Edited by - ryoka012 on 08/16/2013 00:23:09

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 08/16/2013 :  02:35:51  Show Profile  Reply with Quote
DECLARE @str VARCHAR(50) = 'The quick brown fox JuMp over the lazy dog.'
DECLARE @searchStr VARCHAR(10) = 'jump'

IF ( @str LIKE '%'+@Searchstr+'%')
	SELECT SUBSTRING ( REPLACE (@str, LEFT(@str, CHARINDEX(@searchStr, @str)-1), ''), 1, LEN(@searchStr))



--
Chandu
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 08/16/2013 :  02:57:28  Show Profile  Visit SwePeso's Homepage  Reply with Quote
DECLARE @str VARCHAR(50) = 'The quick brown fox JuMp over the lazy dog.'
DECLARE @searchStr VARCHAR(10) = 'jump'

IF ( @str LIKE '%'+@Searchstr+'%' COLLATE LATIN1_GENERAL_BIN)
	SELECT SUBSTRING ( REPLACE (@str, LEFT(@str, CHARINDEX(@searchStr, @str)-1), ''), 1, LEN(@searchStr))



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

ryoka012
Starting Member

Philippines
20 Posts

Posted - 08/16/2013 :  05:40:09  Show Profile  Reply with Quote
thanks Bandi. just hit tje spot.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 08/16/2013 :  05:48:11  Show Profile  Reply with Quote
quote:
Originally posted by ryoka012

thanks Bandi. just hit tje spot.


Welcome

--
Chandu
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.04 seconds. Powered By: Snitz Forums 2000