+ Reply to Thread
Results 1 to 2 of 2

Thread: without function

  1. #1
    Barn Enthusiast guddu is on a distinguished road guddu's Avatar
    Join Date
    Jul 2008
    Location
    Oxford UK
    Posts
    471
    Rep Power
    4

    without function

    hi
    below is my procedure.in this i m using a function to get some coulmns.but instead of function can i do directly in query?
    Code:
    SELECT  TP.PartnerCode AS 'Component Number',
    		M.Name AS 'Component Name',
    		TC.RelatedReference AS 'Delivery Note Reference',
    		TC.RelatedReferenceDate AS 'Delivery Date',
    		LVLProductCode.LookupValue AS 'ProductCode', 
    	    LVLProductDescr.LookupValue AS 'Description', 
    	    LVLPackSize.LookupValue AS 'Pack Size', 
    		Case When dbo.Get_GLCategoryCode(@vnMemberID,TC.RecipientID,LVLProductCode.LookupValue) IS NOT NULL
    			 THEN dbo.Get_GLCategoryCode(@vnMemberID,TC.RecipientID,LVLProductCode.LookupValue) 
    		Else
    			GM.GLCode
    		End AS 'Default GL Category Code',
    	    --GM2.GLCodeDescription AS 'Default GL Category Description'
    		--GM.GLCodeDescription AS 'Default GL Category Description'
    		--TPExInfo.ValueChar AS 'Default GL Category Description',
    		GM.GLCode AS 'Selected GL Category Code',
    		GM.GLCodeDescription AS 'Selected GL Category Description'
    FROM ThreadContent TC
    INNER JOIN bp_directory..allchildren(@vnMemberID) AS AC ON AC.MemberID=TC.SenderID
    INNER JOIN bp_directory..member AS M on M.MemberID = TC.SenderID 
    INNER JOIN TradingPartner AS TP ON TP.MemberID=TC.SenderID AND TP.ProxyLOOKup = 1                
    -- Get the product code
    INNER JOIN LookupValueLine LVLProductCode ON LVLProductCode.MessageID = TC.MessageID
    	                                       AND LVLProductCode.LookupID = @LOOKUPID_PRODUCTCODE                                
    -- Get the description of the product
    INNER JOIN LookupValueLine LVLProductDescr ON LVLProductDescr.MessageID = LVLProductCode.MessageID
    	                                       AND LVLProductDescr.LookupID = @LOOKUPID_PRODUCTDESCRIPTION
    	                                       AND LVLProductDescr.[LineNo] = LVLProductCode.[LineNo]	
    -- Get the pack size of the product
    INNER JOIN LookupValueLine LVLPackSize  ON LVLPackSize.MessageID = LVLProductCode.MessageID
    	                                    AND LVLPackSize.LookupID = @LOOKUPID_PACKSIZE
    	                                    AND LVLPackSize.[LineNo] = LVLProductCode.[LineNo]
    -- Get the selected GL Category
    INNER JOIN LookupValueLine LVLSelGLCat  ON LVLSelGLCat.MessageID = TC.MessageID
    	                                    AND LVLSelGLCat.LookupID = 298553
    
    INNER JOIN BP_Catalogue..GLCategory_Master GM ON GM.MemberID = @vnMemberID and GM.GLCode=LVLSelGLCat.LookupValue 
    
    INNER JOIN TradingPartner_ExtraInfo TPExInfo  ON TPExInfo.MemberID = @vnMemberID
    	                                          AND TPExInfo.PartnerID = TC.RecipientID
    	                                          AND TPExInfo.ExtraInfoID = 46
    WHERE TC.RelatedReferenceDate BETWEEN @vdtDeliveryStartDate AND @vdtDeliveryEndDate
    	  AND TC.RelatedReferenceTypeID = 2
    ORDER BY TP.PartnerCode,TC.RelatedReferenceDate,LVLProductCode.LookupValue
    
    function is here
    Code:
    CREATE FUNCTION [dbo].[Get_GLCategoryCode] 
    (
    	@vnMemberID int,
    	@vnSupplierID int,
    	@vnProductCode int
    )
    RETURNS int
    AS
    BEGIN
    	DECLARE @vnGLCategoryCode int
    
    	Select @vnGLCategoryCode=GLCategoryCOde from BP_Catalogue..GLCategory_Product where
    	MemberId=@vnMemberID and SupplierID=@vnSupplierID and ProductCode=@vnProductCode
    	
    	RETURN @vnGLCategoryCode
    END
    
    Love is physical attraction and mental destruction

  2. #2
    I like Data Cubes too... Lauramc has a spectacular aura about Lauramc has a spectacular aura about Lauramc's Avatar
    Join Date
    Mar 2008
    Location
    Far Far Away
    Posts
    387
    Real Name
    Laura
    Rep Power
    5

    You could do this in a query, but seeing as you have a CASE statement that evaluates the results of this function, you might find it easier to have it separated that way. Is there a logical reason for you to avoid having the function? Are you experiencing performance issues?

    You could use a stored procedure to do the entire script (including the function) if that makes sense, however you should consider whether the code in the function is specific to this one case or will it be used in other queries / procedures.

+ Reply to Thread

Similar Threads

  1. Function USerName(ID)
    By Shem in forum .NET Development
    Replies: 25
    Last Post: July 8th, 2008, 11:32 AM
  2. VB.Net/C# BBCode Function
    By jmurrayhead in forum .NET Code Samples
    Replies: 0
    Last Post: March 20th, 2008, 10:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO