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.
| Author |
Topic |
|
sanjay2988
Starting Member
16 Posts |
Posted - 2008-12-24 : 05:18:51
|
| DECLARE @Sample TABLE ( ticketID INT, siteID INT, ActionCode VARCHAR(20), strDescription VARCHAR(100) ) INSERT @SampleSELECT 9, 2, 'Item', 'Sale Large Pepsi' UNION ALLSELECT 9, 2, 'Item', 'Sale Small Pepsi' UNION ALLSELECT 9, 2, 'DD', 'Discount' UNION ALLSELECT 10, 2, 'DD', 'Discount' UNION ALLSELECT 10, 2, 'CC', 'Credit' UNION ALLSELECT 10, 2, 'Item', 'Sale Fries' UNION ALLSELECT 10, 2, 'Item', 'Sale Large Pepsi'DECLARE @Search TABLE ( data VARCHAR(20) ActionCode VARCHAR(20) )INSERT @SearchSELECT 'Item','%fries%' UNION ALLSELECT 'DD','%discount%'SELECT x.ticketidFROM @Sample AS xINNER JOIN @Search AS s ON x.strDescription LIKE s.dataWHERE x.ActionCode = s.ActionCodeGROUP BY x.TicketIDHAVING COUNT(DISTINCT s.data) = (SELECT COUNT(*) FROM @Search)in above query if user doesnot pass strDescription to search if he passes only Actioncode then it fails.. suppose i want to search all ticketID having Item as actioncode and DD as other then having condition fails.... Kindly suggest. |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-12-24 : 05:30:04
|
| SELECT x.ticketidFROM @Sample AS xINNER JOIN @Search AS s ON x.ActionCode = s.dataWHERE x.strDescription like s.ActionCodeGROUP BY x.TicketIDHAVING COUNT(DISTINCT s.data) = (SELECT COUNT(*) FROM @Search)try it once |
 |
|
|
|
|
|
|
|