| Author |
Topic |
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 00:53:41
|
| hi all,i have a table called email_meassage,columns are like thismsg_id,article_id,msg_sub,Msg_text,msg_status,msg_attachment etc....i have to select some of the columns from this tablelike msg_id,article_id,Msg_textproblem is i want to display only first 25 characters of msg_text after that i have to display like this '...'(3 dots has to be followed by the select msg_text) how we can do this select Regards,DIvya |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 01:01:16
|
| Help!!! Anybody there............ |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-14 : 01:04:33
|
| Simple....select left(Msg_text,25)+'...'Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 01:12:15
|
| hi all,while executing its showing error like thisMsg 102, Level 15, State 1, Procedure FSP_UserID_ByArticleID, Line 25Incorrect syntax near '+'. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-14 : 01:14:58
|
| How its throws error??check this!!select left('ghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjhgyutyubghgjkh',25)+'...'Post your full query!!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 01:20:12
|
| How its throws error??check this!!select left('ghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjhgyutyubghgjkh',25)+'...'Post your full query!!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/Go to Top of Page this wrking fine but my SP is throwing error i dnt knw y... im posting whole SP what i have done USE [FRONTIERS_TEST]GO/****** Object: StoredProcedure [dbo].[FSP_UserID_ByArticleID] Script Date: 12/14/2009 10:43:09 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: DIVYA GR -- Create date: -- Description:-- EXEC FSP_UserID_ByArticleID 5-- ==================== =========================ALTER PROCEDURE [dbo].[FSP_UserID_ByArticleID] @User_ID int, @Article_ID INT =null ASBEGIN SET NOCOUNT ON; IF (@Article_ID = null OR @Article_ID='' OR @Article_ID is Null) BEGIN SELECT FIS_Email_Message_Transactions .Recv_ID as user_mailid, FIS_Email_Message_Transactions .Msg_ID , FIS_Email_Message .Sub AS 'Subject', (select substring (Msg_Text,1,25) +'...' from FIS_Email_Message), (case when FIS_Email_Message_Transactions.Created_Date= GETDATE() then 'Today' when FIS_Email_Message_Transactions.Created_Date = (GETDATE ()-1) then 'yesterday' else FIS_Email_Message_Transactions.Created_Date end ) as SendDate from FIS_Email_Message INNER JOIN FIS_Email_Message_Transactions ON FIS_Email_Message .Msg_ID =FIS_Email_Message_Transactions .Msg_ID where FIS_Email_Message.Sender_ID = @User_ID END ELSE BEGIN SELECT FIS_Email_Message_Transactions .Recv_ID as User_MailID, FIS_Email_Message_Transactions .Msg_ID , FIS_Email_Message .Sub AS 'Subject', FIS_Email_Message .Msg_Text as 'Body', (select Created_Date = case when Created_Date= GETDATE() then 'Today' when Created_Date = (GETDATE ()-1) then 'yesterday' else Created_Date end from dbo.FIS_Email_Message_Transactions )as 'sent date' from FIS_Email_Message INNER JOIN FIS_Email_Message_Transactions ON FIS_Email_Message .Msg_ID =FIS_Email_Message_Transactions .Msg_ID where FIS_Email_Message.Article_ID = @Article_ID ENDEND |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 01:22:51
|
| the table structure is like this......email_messageMsg_ID intArticle_ID intSender_ID intRole_ID intSalutation_ID intSub varchar(2000)Msg_Text textMsgFlag tinyintMsg_Status bitIsFileAttached bitIsDeleted bitCreated_By intCreated_Date datetimeModified_By intModified_Date datetime email_transaction tableMail_Rec_ID intMsg_ID intRecv_Type char(10)Recv_ID varchar(100)Role_ID intMail_Status bitIsDeleted bitCreated_By intCreated_Date datetimeModified_By intModified_Date datetime |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-14 : 01:25:33
|
| <<but my SP is throwing error i>>What is the new error?MadhivananFailing to plan is Planning to fail |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 01:26:53
|
| my error is like this...Msg 512, Level 16, State 1, Procedure FSP_UserID_ByArticleID, Line 21Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-14 : 01:33:52
|
| I suspect the problem on your case (casewhen FIS_Email_Message_Transactions.Created_Date= GETDATE()then 'Today'when FIS_Email_Message_Transactions.Created_Date = (GETDATE ()-1)then 'yesterday'else cast(FIS_Email_Message_Transactions.Created_Date as varchar(20))end ) as SendDateCheck it now...Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-14 : 01:36:35
|
quote: Originally posted by divyaram my error is like this...Msg 512, Level 16, State 1, Procedure FSP_UserID_ByArticleID, Line 21Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Put a where clause in your sub query too..Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 01:36:38
|
| :( again is throwing errorMsg 512, Level 16, State 1, Procedure FSP_UserID_ByArticleID, Line 21Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-14 : 01:37:49
|
quote: Originally posted by divyaram :( again is throwing errorMsg 512, Level 16, State 1, Procedure FSP_UserID_ByArticleID, Line 21Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The Error Clearly says (select substring (Msg_Text,1,25) +'...' from FIS_Email_Message)return more then one value.. Restrict it for one valueSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-12-14 : 01:53:20
|
| HiIn Inner select you will be getting more than 1 value. Try to find why more than 1 value is returned there. You can use Top 1 in inner select to pick first value and avoid this error.-------------------------R... |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-14 : 02:01:31
|
| Thank u all...its wrking fine now.... :)regards,Divya |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-14 : 02:09:40
|
| Good... Started with concatenation '+', travel with 'case', ended with Subquery.. CoolSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-16 : 02:35:56
|
quote: Originally posted by divyaram How its throws error??check this!!select left('ghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhjhgyutyubghgjkh',25)+'...'Post your full query!!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/Go to Top of Page this wrking fine but my SP is throwing error i dnt knw y... im posting whole SP what i have done USE [FRONTIERS_TEST]GO/****** Object: StoredProcedure [dbo].[FSP_UserID_ByArticleID] Script Date: 12/14/2009 10:43:09 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: DIVYA GR -- Create date: -- Description:-- EXEC FSP_UserID_ByArticleID 5-- ==================== =========================ALTER PROCEDURE [dbo].[FSP_UserID_ByArticleID] @User_ID int, @Article_ID INT =null ASBEGIN SET NOCOUNT ON; IF (@Article_ID = null OR @Article_ID='' OR @Article_ID is Null) BEGIN SELECT FIS_Email_Message_Transactions .Recv_ID as user_mailid, FIS_Email_Message_Transactions .Msg_ID , FIS_Email_Message .Sub AS 'Subject', (select substring (Msg_Text,1,25) +'...' from FIS_Email_Message), (case when FIS_Email_Message_Transactions.Created_Date= GETDATE() then 'Today' when FIS_Email_Message_Transactions.Created_Date = (GETDATE ()-1) then 'yesterday' else FIS_Email_Message_Transactions.Created_Date end ) as SendDate from FIS_Email_Message INNER JOIN FIS_Email_Message_Transactions ON FIS_Email_Message .Msg_ID =FIS_Email_Message_Transactions .Msg_ID where FIS_Email_Message.Sender_ID = @User_ID END ELSE BEGIN SELECT FIS_Email_Message_Transactions .Recv_ID as User_MailID, FIS_Email_Message_Transactions .Msg_ID , FIS_Email_Message .Sub AS 'Subject', FIS_Email_Message .Msg_Text as 'Body', (select Created_Date = case when Created_Date= GETDATE() then 'Today' when Created_Date = (GETDATE ()-1) then 'yesterday' else Created_Date end from dbo.FIS_Email_Message_Transactions )as 'sent date' from FIS_Email_Message INNER JOIN FIS_Email_Message_Transactions ON FIS_Email_Message .Msg_ID =FIS_Email_Message_Transactions .Msg_ID where FIS_Email_Message.Article_ID = @Article_ID ENDEND
hi i need one more colums for output....for that it has to find count of 'msg_ID' if the msg_id count is more then one it has to show the no of count only else it has to it has to show the'FIS_Email_Message_Transactions.Mail_Rec_ID' ie to whom the user has forwarded the mail |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-16 : 02:53:45
|
| hi all, we can declare one parameter like @ count, and we check condition for @ count with case statement .... but i m confused on how to do that??? |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-16 : 02:57:16
|
| SELECT FIS_User.First_Name +' '+FIS_User.Last_Name FullName , FIS_Email_Message_Transactions .Recv_ID as user_MailID, --FIS_Email_Message_Transactions .Recv_Type, (case when count (FIS_Email_Message_Transactions .Msg_ID )<> 0 then @count = count (FIS_Email_Message_Transactions .Msg_ID else FIS_Email_Message_Transactions.Mail_Rec_ID end ) FIS_Email_Message .Sub AS 'Subject', |
 |
|
|
divyaram
Posting Yak Master
180 Posts |
Posted - 2009-12-16 : 02:57:40
|
| but its not working..... :( |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-16 : 03:32:28
|
| SELECT FIS_User.First_Name +' '+FIS_User.Last_Name FullName ,FIS_Email_Message_Transactions .Recv_ID as user_MailID, --FIS_Email_Message_Transactions .Recv_Type,(counting = case when count (FIS_Email_Message_Transactions .Msg_ID )<> 0 then count (FIS_Email_Message_Transactions .Msg_IDelse FIS_Email_Message_Transactions.Mail_Rec_ID end)FIS_Email_Message .Sub AS 'Subject',MadhivananFailing to plan is Planning to fail |
 |
|
|
Next Page
|