Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to pass parameter from front end based on requirement then based on that parameter the function would be sorted..

So how can I provide sorting feature in function
Please help me..
SQL
ALTER FUNCTION [dbo].[Func_GetCamp]
(
 @YearID int,
 @FederationID int,
 
 @SortOrder VARCHAR(MAX)
)
RETURNS 
@GetStateDistributionSummary TABLE 
(
 campaignID int,
 campaignName varchar(100),
 campaignControlNumber int,
 DistributionID int,
 AllocationDate datetime,
 DistributionNumber int,
 DistributionAmount decimal(18,2)
)
AS
BEGIN
 
 IF(@CampaignTypeID=0)
	BEGIN
		SET @CampaignTypeID=null
	END
	
	
SET @SortOrder = @SortOrder
 INSERT INTO @GetStateDistributionSummary
 
	SELECT
		campaign.campaignID,
		campaignName =
		CASE 
			WHEN LEN(campaign.name) > 25 THEN SUBSTRING ( campaign.name , 1 , 25 ) + '...'
			ELSE campaign.name
		END,
		CAST(campaign.controlNumber AS int) AS campaignControlNumber,
		allocation.DistributionID,
		allocation.allocationdate,
		Distribution.DistributionNumber,
		SUM(allocationCampaign.allocatedAmount) AS distributionAmount
	from 
		pledgenet.Allocation Allocation,
		pledgenet.allocationCampaign allocationCampaign,
		pledgenet.Distribution Distribution,
		pledgenet.campaign campaign
	WHERE 
		Allocation.YearID = @YearID
	AND 
		Allocation.FederationID = @FederationID
	)
	
	AND
        campaign.stateID =@StateID	
	GROUP BY 
		campaign.campaignID,
		CASE 
			WHEN LEN(campaign.name) > 25 THEN SUBSTRING ( campaign.name , 1 , 25 ) + '...'
			ELSE campaign.name
		END,
		CAST(campaign.controlNumber AS int),
		allocation.DistributionID,
		allocation.allocationdate,
		Distribution.DistributionNumber	
 RETURN 
END


[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 21-May-13 0:10am
v3
Comments
OriginalGriff 21-May-13 6:10am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900