wrong results using Right
Posted on 2005-04-19
I've created the following store procedure:
CREATE PROCEDURE dbo.uspSelectQueries2 @msg1 varchar(3000) output
set @msg1 = ''
Declare cSteps cursor for
select New_Sql, Action_Name, comment from steps_Total where step_no = 694 or step_no = 705 or step_no = 714 or step_no = 715
declare @SQL VARCHAR(500), @QryName VARCHAR(300), @Comment VARCHAR(3000)
FETCH next from cSteps into @Sql, @QryName, @Comment
while @@fetch_status = 0
set @msg1 = @msg1 + right(@QryName, charindex('::', @QryName) ) + ': ' + @Comment + Char(13) + Char(10) + Char(13) + Char(10)
fetch next from cSteps into @sql, @QryName, @Comment
This works fine except for: right(@QryName, charindex('::', @QryName) ).
the first result is fine. It returns something like this: ReturnTable1
the next result will return something like this: s::ResultsOK
What it is doing is based on the length the first time though the following results will return starting from the right to left return the same length as the first result. So if the first result is 10 then all other results will return the first 10 char from right to left. I just want everything from the right of ::