ALTER PROCEDURE selectedrfp
@from datetime,
@to datetime,
@bdename varchar(max),
@status int
AS
BEGIN
DECLARE @query varchar(max)
set @query='
SELECT RS.[RFP_ICode]
,RS.[Client_ICode]
,RS.[Client_Name]
,RS.[Project_Title]
,RS.[Client_Country]
,RS.[RFP_Technology]
,RS.[RFP_Received_Date]
,RS.[Cgvak_Comh_WishList]
FROM dbo.Cgvak_RFP_Status AS RS
INNER JOIN CGVAK_RFP_Status_Master AS RSM
ON RSM.[RFP_Status_Icode]=RS.[RFP_Status]
INNER JOIN CGVAK_RFP_Users AS RU
ON RU.[RFP_User_ICode]=RS.[BDE_Icode]
WHERE RS.[Cgvak_Comh_WishList]=1
AND RS.[RFP_Received_Date] BETWEEN @from AND @to
-- AND RS.[BDE_Name]=@bdename
AND RSM.[RFP_Status_ICode]=@status
AND RU.[RFP_User_Type] IN(1,2,3)'
DECLARE @withoutbde varchar(max)
SET @withoutbde='ORDER BY RS.[RFP_Received_Date] DESC'
DECLARE @withbde varchar(max)
SET @withbde='AND RS.[BDE_Name]=@bdename ORDER BY RS.[RFP_Received_Date] DESC'
IF(@bdename='All')
EXEC (@query + @withoutbde )
ELSE IF(@bdename!='All')
EXEC (@query + @withbde )
END
EXEC selectedrfp @from='2010/01/01',@to='2011/06/22',@bdename='chad',@status=4