Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Creating dynamic search using T-SQL stored procedures
  2. select * from table
  3. where
  4.     (word is like @word1)
  5.     and (word is like @word2)
  6.        
  7. declare @wordtable table(word varchar(20))
  8. declare @table table(word varchar(500))
  9.  
  10. insert @wordtable values('car')
  11. insert @wordtable values('wheel')
  12.  
  13. insert @table values('carwheel')
  14. insert @table values('car')
  15. insert @table values('wheel')
  16. insert @table values('wheelcat')
  17.  
  18. select * from @table t
  19. where not exists (select 1 from @wordtable where t.word not like '%' + word + '%')
  20.        
  21. (word is like @word1)
  22.     and (word is like @word2)