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 2008 Forums
 Transact-SQL (2008)
 Help me at this query

Author  Topic 

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2012-03-04 : 07:33:38
Hi
I have these tables
RawNews(NewsID,Title,Text)
NewsGroup(GroupID,Title,Description)
UsedNewsID(UsedID,NewsID,GroupID)

the scenario is first users add RawNewses and then they wanna add these newses to NewsGroups. (UsedNews table)

now i want to get a status of RawNewses to see which Groups are using a RawNews. if my data was like below

RawNews
1 --- raw1 --- text1
2 --- raw2 --- text2

NewsGroups
1 --- Sport --- sport News
2 --- Political --- Political News
3 --- Economic ---- Economic News

UsedNews
1 --- 1 --- 1
2 --- 1 --- 2
3 --- 2 --- 1
4 --- 2 --- 2
5 --- 2 --- 3

i want the query result like below:
NewsID - Title - Text - Status
1 --- raw1 --- text1 --- sport News Political News
2 --- raw2 --- text2 --- sport News Political News Economic News

thanks

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2012-03-04 : 10:12:31
Hi
I found the solution Myself
i created a Function and used it in select query
Go to Top of Page

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2012-03-04 : 13:13:55
Using for xml path('') in the select is another solution that may be better performance.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-04 : 14:27:19
quote:
Originally posted by mahdi87_gh

Hi
I found the solution Myself
i created a Function and used it in select query


see scenario 3 here
http://visakhm.blogspot.com/2010/01/multipurpose-apply-operator.html



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -