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 |
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-07-15 : 11:24:38
|
| Hi Friends,I need help to get a query.LP_UsermanagementUserId Nickname 2 sambath3 dhina25 kotti89 expert0190 expert02LP_Mail MailId ParentId FromUserId ToUserId Subject Text Attachafile Flag 1 0 2 3 Test1 Test2 12 0 2 3 Test3 Test4 13 1 3 2 Test5 Test6 04 1 2 3 Test7 Test8 15 0 2 89 Test9 Test10 upimages/sam.doc 1 6 5 89 2 Test11 Test12 17 5 2 89 Test13 Test14 18 5 89 2 Test15 Test16 19 5 2 89 Test17 Test18 110 0 2 90 Test19 Test20 111 10 90 2 Test21 Test22 112 10 2 90 Test23 Test24 113 5 89 2 Test25 Test26 upimages/pic1.jpg 0Here i have two tables one for maintaining user details and other one for maintaining Email details sent by usersHere when parentid=0 means the user has first sent the email .when anyone reply to this email ,the mailid will be saved in the parentid field.For your reference in the above table we will consider the first row.Mailid field has 1 ,parentId field has o ,and From field has 2 etcfor this email two reply has been there (i,e) MailId 3 row and MailId 4 row which has parentid 1 and if the flag is 0 for anyone of the row i need to return as IN and If None of the row Flag as 0 i need to return as Out.If U need more explanations , i will explainThis is my test querySELECT M.*,(CASE WHEN M.Attachafile<>'' THEN '<a href='+M.Attachafile+'><img src=upimages/attachment.png height=15 width=20 border=0/></a>' END) as Attached,M.Subject+' ('+CAST((SELECT count(*) FROM LP_MAIL WHERE ParentId=M.MailId) AS VARCHAR(128))+')' AS SubjectText,(CASE WHEN (SELECT TOP 1 Flag FROM LP_mail WHERE ParentId=M.MailId) IS NULL THEN 'OUT' WHEN (SELECT TOP 1 Flag FROM LP_mail WHERE ParentId=M.MailId)=0 THEN 'IN' WHEN (SELECT Top 1 Flag FROM LP_mail WHERE ParentId=M.MailId)=1 THEN 'OUT' END) as ChkFlag,(select Nickname from LP_Usermanagement where UserId=2) Nickname,(select (CASE WHEN Online=1 THEN 'Expert is online!' WHEN Online=0 THEN '' END) from LP_Usermanagement where UserId=2) Online FROM LP_Mail M WHERE (M.FromUserId=2 OR M.ToUserId=2) and M.ParentId=0 Order by MailId DESCThanks in Advance |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-15 : 12:37:15
|
| ok. so what should be output that you're looking at? also are you using sql 2005? |
 |
|
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-07-16 : 00:55:46
|
| Visakh,Thank you for your Reply,I am using Sql server 2000,Please find my expected output belowFrom Subject ChkFlag Attachafile ----------------------------------------------------------------------------------------sambath.ekambaram@g.com Test1 (2) OUT sambath.ekambaram@g.com Test3 (5) IN upimages/sam.docsambath.ekambaram@g.com Test9 (0) OUTsambath.ekambaram@g.com Test19 (2) OUTThanks in Advance |
 |
|
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-07-16 : 04:50:08
|
| Anyone please help me regarding this query.Thanks in Advance |
 |
|
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-07-16 : 07:43:40
|
| Hi friends,Anyone please help me regarding this query.If U need more explanations , i will explainplease help this concernThanks an Advance |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-16 : 12:31:21
|
quote: Originally posted by esambath Visakh,Thank you for your Reply,I am using Sql server 2000,Please find my expected output belowFrom Subject ChkFlag Attachafile ----------------------------------------------------------------------------------------sambath.ekambaram@g.com Test1 (2) OUT sambath.ekambaram@g.com Test3 (5) IN upimages/sam.docsambath.ekambaram@g.com Test9 (0) OUTsambath.ekambaram@g.com Test19 (2) OUTThanks in Advance
this output doesn't make sense . where did you get email values from? these are not specified in posted data.suggest you to repost giving data in below formathttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|
|
|
|
|