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 |
|
reddymade
Posting Yak Master
165 Posts |
Posted - 2006-02-03 : 11:44:36
|
When executed the folloowing stored proc. it seems to be going into loop, Can you please tell me i am doing something wrong with the @bodyAll i am trying to do is concatenate few fields values and store into field emailbody.CREATE PROCEDURE dbo.USP_SendEmailActions (@ModuleID int) ASDECLARE @ErrorCode intDECLARE @TransactionCountOnEntry intDECLARE @actionno nvarchar(50)DECLARE @DueDate datetimeDECLARE @Description nvarchar(150)DECLARE @body nvarchar(1000)SET NOCOUNT ONSET TRANSACTION ISOLATION LEVEL SERIALIZABLESELECT @ErrorCode = @@Error, @TransactionCountOnEntry = @@TranCountIF @ErrorCode <>0BEGIN SET NOCOUNT OFF RETURN @ErrorCodeENDDECLARE @CUR_TEMP CURSORSET @CUR_TEMP = CURSOR SCROLL FOR (Select actionno, CONVERT(varchar(10),DueDate,101) as DueDate,actiondescription from tab_ccsnetactions where modulerecordid = @ModuleID)OPEN @CUR_TEMPBEGIN TRANSACTIONFETCH FIRST FROM @CUR_TEMP INTO @actionno, @DueDate, @descriptionSET @body='ActionNo: '+@actionno+char(13)+'Description: '+@Description+char(13)WHILE @@FETCH_STATUS = 0BEGIN INSERT INTO TABLE_Emails (ActionNo, DueDate, EmailBody) VALUES (@actionno, @DueDate, @body) FETCH NEXT FROM @CUR_TEMP INTO @actionno, @DueDate, @Description SET @body='ActionNo: '+@actionno+char(13)+'Description: '+@Description+char(13)ENDSELECT @ErrorCode = @@ErrorIF @ErrorCode = ' 0'BEGIN IF @@TranCount > @TransactionCountOnEntry COMMIT TRANSACTION CLOSE @CUR_TEMP DEALLOCATE @CUR_TEMP SET NOCOUNT OFF RETURN @ErrorCodeENDELSEBEGIN CLOSE @CUR_TEMP DEALLOCATE @CUR_TEMP ROLLBACK TRANSACTION SET NOCOUNT OFF RETURN @ErrorCodeENDGO Thank you very much for the information. |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-02-03 : 11:54:06
|
Why use the cursor?INSERT INTO TABLE_Emails (ActionNo, DueDate, EmailBody)Select actionno, CONVERT(varchar(10),DueDate,101) as DueDate, 'ActionNo: ' + @actionno + char(13) + 'Description: ' + actiondescription + char(13) as ERmailBodyfrom tab_ccsnetactions where modulerecordid = @ModuleID |
 |
|
|
reddymade
Posting Yak Master
165 Posts |
Posted - 2006-02-07 : 13:40:37
|
Helo Rick,I am using the same way you have asked me to instead of using cursors, But i don't see the concatenated column getting populated in the table. after the insert. Please can you tell me what am i doing wrong.CREATE PROCEDURE dbo.USP_SendEmailActions (@ModuleID int) ASDECLARE @ErrorCode intDECLARE @TransactionCountOnEntry intDECLARE @actionno nvarchar(50)DECLARE @DueDate datetimeDECLARE @Description nvarchar(150)DECLARE @body nvarchar(1000)Set @Body = 'ActionNo: ' + @actionno + char(13) + 'Description: ' + @Description + char(13) + ' as description'INSERT INTO TABLE_Emails (ActionNo, DueDate, Description)Select actionno, CONVERT(varchar(10),DueDate,101) as DueDate, @Body from tab_ccsnetactions where modulerecordid = @ModuleIDGO |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-02-07 : 13:58:18
|
reddymade,Your variables @Description doesn't have data when it is used in this way.What RickD has told was to have the table-field names in the query along with constant text. the variables used in the Insert statement should be derived before reaching the statement or should be taken from a table in the statement.Thats why the following works 'ActionNo: ' + @actionno + char(13) + 'Description: ' + actiondescription + char(13) as ERmailBody and the following doesn't workSet @Body = 'ActionNo: ' + @actionno + char(13) + 'Description: ' + @Description + char(13) + ' as description'..... CONVERT(varchar(10),DueDate,101) as DueDate, @Body |
 |
|
|
reddymade
Posting Yak Master
165 Posts |
Posted - 2006-02-07 : 15:24:07
|
Hello Srinika,I am using the following, still i don't see any data getting into description field under table_emails table.table_emails fields (Id(identity column), actionno, duedate, description(text - 16))CREATE PROCEDURE dbo.USP_SendEmailActions (@ModuleID int) ASDECLARE @ErrorCode intDECLARE @TransactionCountOnEntry intDECLARE @actionno nvarchar(50)DECLARE @DueDate datetimeDECLARE @Description nvarchar(150)DECLARE @body nvarchar(1000)--Set @Body = 'ActionNo: ' + @actionno + char(13) + 'Description: ' + actiondescription + char(13) as EmailBodyINSERT INTO TABLE_Emails (ActionNo, DueDate, Description)Select actionno, CONVERT(varchar(10),DueDate,101) as DueDate, 'ActionNo: ' + @actionno + char(13) + 'Description: ' + actiondescription + char(13) as descriptionfrom tab_ccsnetactions where modulerecordid = @ModuleIDGO |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-07 : 16:07:12
|
You are still using a variable in your SELECT statement. Since you aren't setting it, it is using NULL which depending on your setting could mean that whole column is being set to NULL. Get rid of @actionno from the SELECT. Use the ActionNo column from tab_ccsnetactions instead.quote: 'ActionNo: ' + @actionno + char(13)
Tara Kizeraka tduggan |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-02-08 : 05:25:48
|
Sorry, my bad, forgot to take out the @.. INSERT INTO TABLE_Emails (ActionNo, DueDate, EmailBody)Select actionno, CONVERT(varchar(10),DueDate,101) as DueDate, 'ActionNo: ' + actionno + char(13) + 'Description: ' + actiondescription + char(13) as ERmailBodyfrom tab_ccsnetactions where modulerecordid = @ModuleID |
 |
|
|
|
|
|
|
|