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 |
Pete_N
Posting Yak Master
181 Posts |
Posted - 2012-02-22 : 13:46:28
|
i am trying to build a stored procedure that will take an array of varchar, run a cursor and generate text from each array into a text file. One of the actions in the cursor is to call a stored procedure and parm in a uniqueidentifier. I keep getting a conversion error, but carn't figure it outALTER PROCEDURE [dbo].[spBOSS2012_Submission_BACS_Building]@LedgerkeyArray varchar(200)ASBEGIN SET NOCOUNT ON;Declare @FileName Nvarchar(1000) = '\\Standbymaster\share\bacs.txt'Declare @WriteLine Varchar(1000)DECLARE @xpreurn_Value INTDECLARE @return_value int, @RTNSTR varchar(200)Declare @FirstFile as bit = 0Create table #tempArrayTable (rid varchar(500))Insert into #tempArrayTable (rid)(select value from dbo.BOSS2012_Split(@LedgerkeyArray,';'))DECLARE @ArrayItem varchar(100)DECLARE @LedgerKey_Cursor CURSORSET @LedgerKey_Cursor = CURSOR FAST_FORWARD FOR select rid from #tempArrayTableOPEN @LedgerKey_CursorFETCH NEXT FROM @LedgerKey_Cursor INTO @ArrayItemWHILE @@FETCH_STATUS = 0 BEGINDeclare @Ledger as uniqueidentifier = CAST(@ArrayItem AS UniqueIdentifier) /* need to convert back to uniqueidentifier */ Print @Ledger/* HDR1 */EXEC @return_value = [dbo].[spBOSS2012_Submission_BACS_HDR1] @LedgerKey = @Ledger, @RTNSTR = @RTNSTR OUTPUTif @return_value <> 0 Begin return 1 End If @FirstFile = 0 BEGIN /* WRITE HDR1 */ Set @WriteLine = 'echo ' + @RtnStr + '> ' + @FileName exec @xpreurn_Value = master..xp_cmdshell @WriteLine , no_output END If @FirstFile = 1 BEGIN /* WRITE HDR1 */ Set @WriteLine = 'echo ' + @RtnStr + '>> ' + @FileName exec @xpreurn_Value = master..xp_cmdshell @WriteLine , no_output ENDset @FirstFile = 1 If @xpreurn_Value <> 0 Begin /* Error Writing File */ return 1 EndFETCH NEXT FROM @LedgerKey_Cursor INTO @ArrayItemENDClose @LedgerKey_Cursordeallocate @LedgerKey_CursorENDDECLARE @return_value intEXEC @return_value = [dbo].[spBOSS2012_Submission_BACS_Building] @LedgerkeyArray = N'''5E743F49-4AE1-442C-A33D-000590592472'';''7AA73D9E-96C7-4183-B7DA-0027A9CFA8D0'';''F541DFD6-A570-415A-8C4C-09C001F74775'';''5705F61A-0915-4937-A948-0A2C8C916898'''SELECT 'Return Value' = @return_valueerrorMsg 8169, Level 16, State 2, Procedure spBOSS2012_Submission_BACS_Building, Line 32Conversion failed when converting from a character string to uniqueidentifier. |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-22 : 14:22:23
|
Can you do a PRINT on the @ArrayItem before you try casting to see what it is. It appears that you have too many single quotes in the EXEEC call. Maybe try calling like:EXEC @return_value = [dbo].[spBOSS2012_Submission_BACS_Building]@LedgerkeyArray = N'5E743F49-4AE1-442C-A33D-000590592472;7AA73D9E-96C7-4183-B7DA-0027A9CFA8D0;F541DFD6-A570-415A-8C4C-09C001F74775;5705F61A-0915-4937-A948-0A2C8C916898' |
 |
|
Pete_N
Posting Yak Master
181 Posts |
Posted - 2012-02-22 : 15:14:24
|
spot on, sometimes its the easy things that catch us out |
 |
|
|
|
|
|
|