Thank you Jack and Uri,
Both your advice fixed it.
Why is it that I had to set the string to ''? and there was a null
result in the set, and so ISNULL took care of that wee issue.
-Brian
Below is the working code:
DECLARE @string varchar(8000), @work varchar(10), @omBranchID int
set @omBranchID = 17674
declare MyCursor CURSOR FOR SELECT dbo.omStatus.omStatusAlphaShort
FROM dbo.omBranchStatus INNER JOIN
dbo.omStatus ON
dbo.omBranchStatus.omStatusID = dbo.omStatus.omStatusID
WHERE dbo.omBranchStatus.omBranchID = @omBranchID AND
omBranchStatus.omBranchStatusComplete = 0
Order By omStatus.omStatusRank
set @string = ''
OPEN MyCursor
FETCH MyCursor INTO @work
WHILE @@FETCH_STATUS = 0
BEGIN
set @string = @string + ' ' + ISNULL(@work,'')
FETCH MyCursor INTO @work
END
DEALLOCATE MyCursor
PRINT @string
[quoted text, click to view] On Mar 19, 1:46 am, "Jack Vamvas" <DEL_TO_RE...@del.com> wrote:
> How exactly is it jamming up?
> Try putting SET @string = '' , prior to the DECLARE CURSOR starting ,
> and reply with what result you get?
>
> Jack Vamvas
> ___________________________________
> Advertise your IT vacancies for free at -
http://www.ITjobfeed.com >
> <mang...@gmail.com> wrote in message
>
> news:1174281945.121735.98210@n76g2000hsh.googlegroups.com...
>
> >I am having a problem with returning a string of values from the
> > table, this will be part of a scalar function but here is where the
> > code is jamming up.
>
> > Code:
> > DECLARE @string as nvarchar(200), @work nvarchar(200), @omBranchID
> > int
> > set @omBranchID = 11601
> > declare MyCursor CURSOR FOR SELECT dbo.omStatus.omStatusAlphaShort
> > FROM dbo.omBranchStatus INNER JOIN
> > dbo.omStatus ON
> > dbo.omBranchStatus.omStatusID = dbo.omStatus.omStatusID
> > WHERE dbo.omBranchStatus.omBranchID = @omBranchID AND
> > omBranchStatus.omBranchStatusComplete = 0
> > Order By omStatus.omStatusRank
>
> > OPEN MyCursor
> > FETCH MyCursor INTO @work
> > WHILE @@FETCH_STATUS <> -1
> > BEGIN
>
> > set @string = @string + @work
>
> > FETCH MyCursor INTO @work
> > END
> > DEALLOCATE MyCursor
>
> > PRINT @string
>
> > What is the solution to this and what is the problem called (so I can
> > learn about it)