Create function without using Cursor

  • Can we Made below function without using Cursor??Please help

    ALTER FUNCTION [CRM].[SUNDRY_JOB_WORK] (@RequestId BIGINT)

    RETURNS varchar(1000)

    AS

    BEGIN

    declare @JobWork Varchar(200)

    declare @JobWorks Varchar(1000)

    set @JobWorks='';

    DECLARE curAllTables CURSOR FOR

    select aa.DESCRIPTION from TECH_REQUEST_JOB_TYPE_DETAIL TT inner join MST_JOB_WORK_TYPES aa ON TT.JOB_WORK_ID=aa.JOB_WORK_TYPE_ID

    WHERE REQUEST_ID=@RequestId

    OPEN curAllTables

    FETCH NEXT FROM curAllTables INTO @JobWork

    WHILE (@@FETCH_STATUS=0)

    BEGIN

    set @JobWorks = @JobWorks+@JobWork+','

    FETCH NEXT FROM curAllTables INTO @JobWork

    END

    set @JobWorks=substring(@JobWorks,1,LEN(@JobWorks)-1)

    CLOSE curAllTables

    deallocate curAllTables

    RETURN @JobWorks

    END

  • Check out this article: Creating a comma-separated list (SQL Spackle)[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply