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 2005 Forums
 Transact-SQL (2005)
 search advanced

Author  Topic 

trinm1987
Starting Member

2 Posts

Posted - 2009-06-26 : 23:00:42
I have database below:
table (idbook, idpublish,title)
idbook idpublish title
1 1 'van hoc viet nam can dai'
2 1 'tu hoc english'
3 1 tu hoc lap trinh sql server 2005
4 2 van hoc nuoc ngoai
5 3 development webiste with .net 2005
i have productore
@txtSearch nvarchar(200)

Begin

Select ...

from book

where...

end

when @txtSearch='van hoc can dai'==>
idbook
1
4
when @txtSearch='lap trinh sql 2005'==>
idbook
3
5

Thanks you very much

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-06-26 : 23:13:16
declare @txtSearch nvarchar(200)
select @txtSearch ='van hoc can dai'

select idbook from book where title like '%'+@txtSearch +'%'
or select idbook from book where patindex('%'+@txtSearch +'%',username)>0
Go to Top of Page

trinm1987
Starting Member

2 Posts

Posted - 2009-06-26 : 23:27:46
are you sure?
When you enter @txtSearch ='van hoc can dai'
database not this record so it don't search
my idea, we can search word, ex:'van hoc', 'can dai','van'....
but i don't coding
you can help me
Thanks you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-27 : 01:31:16
seeing your output, i think what you need is to pass the strings to be searched in following format

@txtSearch ='van hoc,can dai'. then in query parse the string based on , delimited and then do your search. something like

SELECT t.*
FROM table t
INNER JOIN dbo.ParseValues (@txtSearch,',') f
ON t.title LIKE '%'+ f.Val + '%'

parsevalues can be found in below link

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=128201

Go to Top of Page
   

- Advertisement -