Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Incoporate the UDF functionality into the Sp

Incoporate the UDF functionality into the Sp

Scheduled Pinned Locked Moved Database
csharpasp-netsharepointcom
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    Good Day All I have an Sp and UDF. the UDF cant take #tables. so i want to incoporate the functionality that is being provided by the udf and make it part of the code. the first part of my statement creates a solid table that is being used in the UDF

    truncate table temp
    INSERT INTO temp
    SELECT MTN.ID,S.DESCR,ISNULL(MTN.CYCLETEMPLATE,C.CYCLES) AS CYCLETEMPLATE,MTN.ACTV AS [ACTV]
    FROM TBL_STAFF S
    INNER JOIN MTM_ACTV_STAFF MTN ON
    S.ID = MTN.STAFF
    LEFT OUTER JOIN MTM_ACTV_STAFF_CYCLE C
    ON C.IDL = MTN.ID
    END
    ELSE
    BEGIN
    SELECT MTN.ID,S.DESCR,ISNULL(MTN.CYCLETEMPLATE,C.CYCLES) AS CYCLETEMPLATE,MTN.ACTV AS [ACTV]
    into temp
    FROM TBL_STAFF S
    INNER JOIN MTM_ACTV_STAFF MTN ON
    S.ID = MTN.STAFF
    LEFT OUTER JOIN MTM_ACTV_STAFF_CYCLE C
    ON C.IDL = MTN.ID
    END

    and later in my Sp i have this line of statement

    SELECT DESCR, dbo.GetSortedString(Cast(NULL AS varchar(8000))) AS CycleIdList,ACTV
    INTO #TempSummary
    FROM temp (NOLOCK)
    GROUP BY DESCR,ACTV
    ORDER BY DESCR,ACTV

    which has no problem and later i want to update the Filed in the #TempSummary table like this

    UPDATE #TempSummary
    SET CycleIdList = dbo.Concat(#TempSummary.Descr,#TempSummary.actv)

    now the problem is here, the Concat is the UDF. defined like this

    create FUNCTION [dbo].[Concat] (@Name varchar(50),@Actv int)
    RETURNS varchar(max)
    WITH EXECUTE AS CALLER
    AS
    BEGIN
    Declare @s varchar(max)
    SET @s = ''

    SELECT @s = @s + IsNull(',' + Cast(Cycletemplate AS varchar), '')
    FROM temp (NOLOCK)
    WHERE temp.Descr = @Name And temp.Actv = @Actv
    GROUP BY Cycletemplate
    ORDER BY Cycletemplate
    IF (@S IS NOT NULL) AND (@S <> '') SET @S = SubString(@s, 2, Len(@S)-1)
    RETURN @S
    END

    now i want to incoporate the functionality of the UDF and get rid of it. The UDF use the Temp created in the First example code based on the two fields. and generate the string and update the table #TempSummary. How can i incoporate this functionlity without using UDF. Thanks

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups