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-06-08 : 02:25:19
|
| Hi Experts Please help this query I have one table LP_MailLP_MailMailId,ParentId,FromUserId,ToUserId,Subject,Text,Flag1 0 2 3 Regardingdaily NULL 12 0 2 3 Regardingdaily NULL 13 1 3 2 Regardingdaily NULL 14 1 2 3 Regardingdaily NULL 15 0 2 89 Asp.net price 16 5 89 2 Asp.net 20$ 0 outputSubject FlagRegarding daily updates(0) OUTRegarding daily updates(0) OUTAsp.net(1) INThis is my test query SELECT M.*,M.Subject+' ('+CAST((select count(*) from LP_MAIL where ParentId=M.MailId) AS VARCHAR(128))+')' AS SubjectText,(CASE WHEN (select Flag from LP_mail where ParentId=M.MailId)=0 THEN 'IN' WHEN (select Flag from LP_mail where ParentId=M.MailId)=1 THEN 'OUT' END)FROM LP_Mail M WHERE M.FromUserId=2 and M.ParentId=0We got the errorServer: Msg 512, Level 16, State 1, Line 1Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.Thanks advance |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-06-08 : 05:12:40
|
| try like thisSELECT M.*,M.Subject+' ('+CAST((select count(*) from @LP_MAIL where ParentId=M.MailId) AS VARCHAR(128))+')' AS SubjectText,CASE WHEN m.Flag=1 THEN 'IN' ELSE 'OUT' ENDFROM @LP_Mail M INNER JOIN @LP_mail p ON p.parentid = m.mailidWHERE M.FromUserId=2 and M.ParentId=0 |
 |
|
|
|
|
|
|
|