Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. SELECT *
  2. FROM [VW_EMAIL_ALERT]
  3. WHERE ([SEARCH] LIKE '%this%' AND ([SEARCH] LIKE '%that%' OR [SEARCH] LIKE '%other%'))
  4.  
  5. select id
  6. from keywords
  7. where keyword = 'this'
  8. intersect
  9. select id
  10. from keywords
  11. where keyword in ( 'that','other')
  12.  
  13. DECLARE
  14. @strSQL NVARCHAR(MAX) = ''
  15.  
  16. CREATE TABLE #tmp
  17. (
  18. Result_Query VARCHAR(MAX)
  19. )
  20.  
  21. INSERT INTO
  22. #tmp
  23. SELECT
  24. 'SELECT * FROM [VW_EMAIL_ALERT] WHERE ([SEARCH] = ''%this%'' AND ([SEARCH] = ''%that%'' OR [SEARCH] = ''%other%''))'
  25.  
  26. UNION
  27.  
  28. SELECT
  29. 'SELECT * FROM [VW_EMAIL_ALERT] WHERE ([SEARCH] = ''%this1%'' AND ([SEARCH] = ''%that1%'' OR [SEARCH] = ''%other1%''))'
  30.  
  31. SELECT
  32. @strSQL = @strSQL + Result_Query + ';'
  33. FROM
  34. #tmp
  35.  
  36. SET
  37. @strSQL = LEFT(@strSQL, LEN(@strSQL) - 1)
  38.  
  39. PRINT @strSQL
  40. EXEC(@strSQL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement