Hi im trying to do an if statement in SP but i cannot seem to get it working. if the orderdate is null then it needs to run the first oneelse the otherUSE [Melville]GO/****** Object: StoredProcedure [dbo].[SP_EnabledCategories] Script Date: 06/28/2013 14:17:25 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[SP_EnabledCategories] -- Add the parameters for the stored procedure here @ShowId int = 0, @showdate datetime = 0, @orderdate datetime = null, if (@orderdate = null) BEGIN AS -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure hereselect @showdate = builddate from show where showid=@showidSELECT TOP 9999999 [CategoryId] ,[ParentCategoryId] ,[Description] ,[DisplayOrder] ,[FilePath] ,[FileName] ,[IsDeletedOnOnlineOrdering] ,[IsDeletedOnClick] ,[StandInfoRequired] ,[DaysBeforeBuildDateToDisable] ,[CanHaveSeperateDeliveryAddress] ,datediff(d,getdate(), case when @showdate) FROM [Melville].[dbo].[Category] where ((CategoryId not in (select CategoryId from ShowDisabledCategory where ShowId=@Showid)) ) and (datediff(d,getdate(),@showdate) >DaysBeforeBuildDateToDisable) order by parentcategoryid, DisplayOrder ENDELSEbeginAS -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure hereselect @orderdate = CustomDate from show where showid=@showidSELECT TOP 9999999 [CategoryId] ,[ParentCategoryId] ,[Description] ,[DisplayOrder] ,[FilePath] ,[FileName] ,[IsDeletedOnOnlineOrdering] ,[IsDeletedOnClick] ,[StandInfoRequired] ,[DaysBeforeBuildDateToDisable] ,[CanHaveSeperateDeliveryAddress] ,datediff(d,getdate(), case when @orderdate) FROM [Melville].[dbo].[Category] where ((CategoryId not in (select CategoryId from ShowDisabledCategory where ShowId=@Showid)) ) and (datediff(d,getdate(),@orderdate) >DaysBeforeBuildDateToDisable) order by parentcategoryid, DisplayOrder END