I have a function nested in stored procedure that have parameters in SQL server below but not work.

```
CREATE FUNCTION [dbo].[Select_ByStation1] (@Station NVARCHAR (20), @BrqDateStart DATETIME = NULL, @BrqDateEnd   DATETIME = NULL)
RETURNS TABLE
AS

IF ((@BrqDateStart IS NOT NULL)AND(@BrqDateEnd IS NOT NULL))
    BEGIN
     RETURN 
    ( SELECT * FROM dbo.Select_ByStation(@Station)AS TAB    
      WHERE TAB.BrqDate BETWEEN (@BrqDateStart)AND(DATEADD(S,-1, DATEADD(D, 1, @BrqDateEnd))));
    END

    ELSE IF ((@BrqDateStart IS NULL)OR(@BrqDateEnd IS NULL))
    BEGIN

     RETURN 
    ( SELECT * FROM dbo.Select_ByStation(@Station)AS TAB);
    END 
GO

```

and i get this errors

> 
> Msg 156, Level 15, State 1, Procedure Select\_ByStation1, Line 7
>  Incorrect syntax near the keyword 'IF'. Msg 178, Level 15, State 1,
>  Procedure Select\_ByStation1, Line 9 A RETURN statement with a return
>  value cannot be used in this context. Msg 178, Level 15, State 1,
>  Procedure Select\_ByStation1, Line 17 A RETURN statement with a return
>  value cannot be used in this context.
> 
> 
>