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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select from table with no relation

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]

Go to Top of Page

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-05-21 : 06:50:11
Thanks khtan,
Please refer to http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=125967
Go to Top of Page

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]

Go to Top of Page

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 | categ1
102 | categ2

KeyWords:
501 | mymail1 | 101
502 | mycat2 | 102

Expected o/p: UserCategories filled:

1 | 101
2 | 102

To 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 @data
SELECT 101, 'email' UNION ALL
SELECT 102, 'address'

DECLARE @search varchar(100)

SELECT @search = 'myemailaddress@gmail.com'

SELECT *
FROM @data
WHERE @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

Go to Top of Page

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" ?
Go to Top of Page
   

- Advertisement -