Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *
- FROM [VW_EMAIL_ALERT]
- WHERE ([SEARCH] LIKE '%this%' AND ([SEARCH] LIKE '%that%' OR [SEARCH] LIKE '%other%'))
- select id
- from keywords
- where keyword = 'this'
- intersect
- select id
- from keywords
- where keyword in ( 'that','other')
- DECLARE
- @strSQL NVARCHAR(MAX) = ''
- CREATE TABLE #tmp
- (
- Result_Query VARCHAR(MAX)
- )
- INSERT INTO
- #tmp
- SELECT
- 'SELECT * FROM [VW_EMAIL_ALERT] WHERE ([SEARCH] = ''%this%'' AND ([SEARCH] = ''%that%'' OR [SEARCH] = ''%other%''))'
- UNION
- SELECT
- 'SELECT * FROM [VW_EMAIL_ALERT] WHERE ([SEARCH] = ''%this1%'' AND ([SEARCH] = ''%that1%'' OR [SEARCH] = ''%other1%''))'
- SELECT
- @strSQL = @strSQL + Result_Query + ';'
- FROM
- #tmp
- SET
- @strSQL = LEFT(@strSQL, LEN(@strSQL) - 1)
- PRINT @strSQL
- EXEC(@strSQL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement