Friday, January 22, 2010

SP

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author : Sumit
-- Optimised By : Ashutosh Yadav
-- Create date : 26 April 2007
-- Description : This procedure selects all merchants by status(0 = All, 1 = Active)
-- =============================================
ALTER PROCEDURE [dbo].[usp_GetAllMerchants]
@Status smallint
AS
BEGIN TRY
SET NOCOUNT ON;
IF @Status = 0
BEGIN
SELECT mm.*,am.AffNetworkName,(CASE MerchantStatus WHEN 1 THEN 'Active' WHEN 0 THEN 'InActive' when -1 then 'Recover' END) as MStatus,
(Case MerchantStatus when 1 then 'Deactivate' when 0 then 'Activate' when -1 then 'Recover' end) as Act,
(Case MerchantStatus when 1 then 'Delete' when 0 then 'Delete' end) as Del
FROM tblMerchantMaster mm INNER JOIN tblAffiliateNetworkMaster am ON am.AffiliateId = mm.AffiliateId Where mm.MerchantStatus = 0
END

ELSE IF @Status = 1
BEGIN
SELECT mm.*,am.AffNetworkName,(CASE MerchantStatus WHEN 1 THEN 'Active' WHEN 0 THEN 'InActive' when -1 then 'Recover' END) as MStatus,
(Case MerchantStatus when 1 then 'Deactivate' when 0 then 'Activate' when -1 then 'Recover' end) as Act,
(Case MerchantStatus when 1 then 'Delete' when 0 then 'Delete' end) as Del
FROM tblMerchantMaster mm INNER JOIN tblAffiliateNetworkMaster am ON am.AffiliateId = mm.AffiliateId
WHERE mm.MerchantStatus = 1
END

ELSE IF @Status = 2
BEGIN
SELECT mm.MerchantId,mm.MerchantName,am.AffNetworkName
FROM tblMerchantMaster mm INNER JOIN tblAffiliateNetworkMaster am ON am.AffiliateId = mm.AffiliateId
WHERE mm.MerchantStatus = 1
END
END TRY
BEGIN CATCH
insert into tbldberrorlog Values (ERROR_NUMBER(), ERROR_MESSAGE(), GETDATE(), 'usp_GetAllMerchants')
END CATCH

No comments:

Post a Comment