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
 General SQL Server Forums
 New to SQL Server Programming
 Where

Author  Topic 

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2008-07-25 : 02:56:56
Is there a Where Statement where it will results only search string you use?

Example

Column
I like dogs.
Dogs are stongs


I need a where function where it results that have the word dogs

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-25 : 02:58:45
where ColX like '%dogs%'

Em
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-25 : 09:31:51
Chk this.,

select * from table_name where column_name like '%dog%'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-25 : 09:41:19
quote:
Originally posted by VGuyz

Chk this.,

select * from table_name where column_name like '%dog%'


Already suggested. You need to give new solution if you have

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-25 : 10:41:32
quote:
Originally posted by madhivanan

quote:
Originally posted by VGuyz

Chk this.,

select * from table_name where column_name like '%dog%'


Already suggested. You need to give new solution if you have

Madhivanan

Failing to plan is Planning to fail


which is what he seldom does
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-25 : 10:43:21
quote:
Originally posted by madhivanan

quote:
Originally posted by VGuyz

Chk this.,

select * from table_name where column_name like '%dog%'


Already suggested. You need to give new solution if you have

Madhivanan

Failing to plan is Planning to fail


i have one

select * from table_name where patindex('%dog%',column_name) >0
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-07-25 : 11:36:31
As do I


IF OBJECT_Id('dbo.fn_regex') IS NOT NULL DROP FUNCTION dbo.fn_regex
GO

CREATE FUNCTION dbo.fn_regex(
@pattern VARCHAR(255)
, @matchstring TEXT
)
RETURNS INT

AS BEGIN
DECLARE @obj INT SET @obj = -1
DECLARE @res INT SET @res = -1
DECLARE @match BIT SET @match = 0

-- Make the @res Object.
EXEC @res = sp_OACreate 'VBScript.RegExp', @obj OUT
IF (@res <> 0) RETURN -1

-- Assign the Pattern to it.
EXEC @res = sp_OASetProperty @obj, 'Pattern', @pattern
IF (@res <> 0) RETURN -2

-- Set to ignore Case
EXEC @res = sp_OASetProperty @obj, 'IgnoreCase', 1
IF (@res <> 0) RETURN -3

-- Execute the regular expression
EXEC @res = sp_OAMethod @obj, 'Test',@match OUT, @matchstring
IF (@res <> 0) RETURN -4

-- Cleanup the object
EXEC @res = sp_OADestroy @obj

-- Return the results
RETURN @match
END
GO

SELECT * FROM table_name WHERE dbo.fn_regex('dog', table_name.column_name) = 1


-------------
Charlie
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-25 : 12:08:55
ah but... OP wanted to search for the word DOGS not DOG ...lol

Em
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-07-27 : 09:13:08
Full text index?
Go to Top of Page
   

- Advertisement -