DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

without function

This is a discussion on without function within the Microsoft SQL Server forums, part of the Databases category; hi below is my procedure.in this i m using a function to get some coulmns.but instead of function can i ...

Go Back   DeveloperBarn Forums > Databases > Microsoft SQL Server

  #1  
Old July 15th, 2008, 10:59 AM
guddu's Avatar
Barn Enthusiast
 
Join Date: Jul 2008
Location: Oxford UK
Posts: 334
Rep Power: 2
guddu is on a distinguished road
Default 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
Reply With Quote
  #2  
Old July 15th, 2008, 04:02 PM
Lauramc's Avatar
I like Data Cubes too...
 
Join Date: Mar 2008
Real name: Laura
Location: Far Far Away
Posts: 130
Rep Power: 3
Lauramc will become famous soon enoughLauramc will become famous soon enough
Default

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 With Quote
Reply

  DeveloperBarn Forums > Databases > Microsoft SQL Server

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Function USerName(ID) Shem .Net Development 25 July 8th, 2008 10:32 AM
VB.Net/C# BBCode Function jmurrayhead .Net Code Samples 0 March 20th, 2008 09:44 AM


All times are GMT -4. The time now is 10:59 AM.


Copyright ©2008-2010, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.2