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 2000 Forums
 SQL Server Development (2000)
 Searching specific word

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-12-16 : 09:26:02
Muhammad Ali writes "how can i searching specific word using SQL command
for example i have "my car is blue" and "that is my car" in Microsoft SQL Server 7.0 database. What i want is if i search for word "car", the word of "my car is blue" and "that is my car" will display in my result page.

Thank you."

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-12-16 : 12:17:49
WHERE ColumnName LIKE '%car%'

Tara
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-12-16 : 14:45:12
Tara....you get all the hard ones....

what s/he really means more than likely, is every column in every table...

come on, you can tell us....



Brett

8-)
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-12-17 : 01:15:53
How difficult is that?

http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm


Owais

We make a living out of what we get, but we make a life out of what we give.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-12-17 : 12:17:01
Cool...I think I saw that before...must've forgot and wrote my own

AND He didn't use a cursor...

Anyway, mine counts occurances as well as hits...


-- CREATE TABLE myTable99 ( TABLE_SCHEMA sysname
-- , TABLE_NAME sysname
-- , COLUMN_NAME sysname
-- , ORDINAL_POSITION int
-- , Occurs int
-- , SysTime datetime
-- , SearchString varchar(80)
-- , RowNum int IDENTITY(1,1))
-- GO


SET NOCOUNT ON

DECLARE @SQL varchar(8000), @Sargable varchar(80), @Count int
, @TABLE_SCHEMA sysname, @TABLE_NAME sysname, @COLUMN_NAME sysname, @ORDINAL_POSITION int

SELECT @Sargable = 'PruSelect'

DECLARE insaneCursor CURSOR FOR
SELECT t.TABLE_SCHEMA,c.TABLE_NAME, c.COLUMN_NAME, c.ORDINAL_POSITION
FROM INFORMATION_SCHEMA.Columns c INNER JOIN INFORMATION_SCHEMA.Tables t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE c.DATA_TYPE IN ('char','nchar','varchar','nvarchar','text','ntext')
AND t.TABLE_TYPE = 'BASE TABLE'



OPEN insaneCursor

FETCH NEXT FROM insaneCursor INTO @TABLE_SCHEMA, @TABLE_NAME, @COLUMN_NAME, @ORDINAL_POSITION

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @SQL = 'INSERT INTO myTable99 (TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION'
+',Occurs, SysTime, SearchString) SELECT '
+ '''' + @TABLE_SCHEMA + '''' + ','
+ '''' + @TABLE_NAME + '''' + ','
+ '''' + @COLUMN_NAME + '''' + ','
+ CONVERT(varchar(3),@ORDINAL_POSITION) + ','
+ 'COUNT(*)'
+ ',GetDate()'
+ ','+''''+ @Sargable + ''''
+ ' FROM [' + @TABLE_NAME
+ '] WHERE [' + @COLUMN_NAME + '] Like '
+ ''''+ '%' + @Sargable + '%' + ''''
--SELECT @SQL
EXEC(@SQL)
IF @@ERROR <> 0
BEGIN
SELECT @SQL
SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @TABLE_NAME
GOTO Error
END
FETCH NEXT FROM insaneCursor INTO @TABLE_SCHEMA, @TABLE_NAME, @COLUMN_NAME, @ORDINAL_POSITION
END

SELECT * FROM myTable99 WHERE Occurs <> 0


Error:
CLOSE insaneCursor
DEALLOCATE insaneCursor

GO

--DROP TABLE myTable99
--GO








Brett

8-)
Go to Top of Page
   

- Advertisement -