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 |
|
pyu.agrawal
Starting Member
29 Posts |
Posted - 2009-05-21 : 06:25:39
|
Hi,I have four tables:UserData: ID | .... | .. Categories: CategoryID | CategoryName KeyWords: KeywordID | Keyword | CategoryID UserCategories: ID | CategoryID When data is inserted into UserData, based on a keywords, appropriate categories are saved in the UserCategories table. Now the problem I have is: When a category is edited, I need to assign categories to Users automatically. All records from UserCategories would be deleted, and new mappings saved.Now I do I write the query, to select ID from UserData, match for keywords from KeyWords table, and save the CategoryID in UserCategories.This is urgent.Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-21 : 06:29:19
|
please provide some sample data and the expected result KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pyu.agrawal
Starting Member
29 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-21 : 06:54:05
|
i don't understand what do you mean here. I mean some sample data for all the table you listed here and how do you want the result to be KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pyu.agrawal
Starting Member
29 Posts |
Posted - 2009-05-21 : 07:05:31
|
| UserData:ID| KeyData | .... 1 | mail1@gmail.com | ....2 | mycat@gmail.com | ....Categories:101 | categ1102 | categ2KeyWords:501 | mymail1 | 101502 | mycat2 | 102Expected o/p: UserCategories filled:1 | 1012 | 102To put in words, KeyData from UserData table would be checked with KeyWords. Refer the above link.DECLARE @data TABLE( ID int, keyword varchar(10))INSERT INTO @dataSELECT 101, 'email' UNION ALLSELECT 102, 'address'DECLARE @search varchar(100)SELECT @search = 'myemailaddress@gmail.com'SELECT *FROM @dataWHERE @search LIKE '%' + keyword + '%'The example you gave yestarday. But in this case, ID wont be provided, but it loop from the 1st to the last records from the userdata table |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-05-21 : 11:46:55
|
| How does the keywork "mymail1" map to UserData.KeyData vlaue "mail1@gmail.com" ? |
 |
|
|
|
|
|
|
|