Not giving an error but not getting records back yet since the where clause is still kicking my butt.

The Scope parameter is for specifying which field the From and To date range encompus. If the Scope is CreatedDate then the where clause will be looking in that field. If the Scope is LastUpdated then @Scope looks at that.

So I am trying to get something like this to work.

VB Code:
  1. WHERE
  2.         IF (@Scope = 'Created')
  3.             BEGIN
  4.                 (((@From Is Null) OR (CONVERT(nvarchar(10), [tblLoans].Created, 101) >= @From)) AND ((@To Is Null) OR (CONVERT(nvarchar(10), [tblLoans].Created, 101) <= @To)))
  5.                     AND
  6.             END
  7.         IF (@Scope = 'Last Updated')
  8.             BEGIN
  9.                 (((@From Is Null) OR (CONVERT(nvarchar(10), [tblLoans].Last_Updated, 101) <= @From)) AND ((@To Is Null) OR (CONVERT(nvarchar(10), [tblLoans].Last_Updated, 101) <= @To)))
  10.                     AND
  11.             END
  12.         IF (@Scope = 'Date Submitted')
  13.             BEGIN
  14.                 (((@From Is Null) OR (CONVERT(nvarchar(10), [tblLoans].DateSubmitted, 101) >= @From)) AND ((@To Is Null) OR (CONVERT(nvarchar(10), [tblLoans].DateSubmitted, 101) <= @To)))
  15.                     AND
  16.             END
  17.         ((@Status Is Null) OR ([tblLoans].Status = @Status))