Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Syntax error

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-03-09 : 09:35:33
What's wrong with this sp ? I get the error 'Incorrect syntax near the keyword where.' If I use between instead like this it works
--MaxDateOut between @strStartDate and @strEndDate
but I want to include the start and end dates. MaxDateOut finds the latest date in a view which groups the data.

I have also tried taking the 'and' out before the 'where' and same error.

CREATE PROCEDURE spRMU_GetChaseFiles

@strStartDate datetime,
@strEndDate datetime,
@strDepartment nvarchar(100),
@strDivision nvarchar(100)

AS

SELECT *
FROM vweChaseFilesOut

WHERE

Dept like '%'+@strDepartment+'%' and
Division like '%'+@strDivision+'%' and
where MaxDateOut >= @strStartDate and <= @strEndDate
order by MaxDateOut asc
GO

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-09 : 09:38:08
quote:
Originally posted by Pinto

What's wrong with this sp ? I get the error 'Incorrect syntax near the keyword where.' If I use between instead like this it works
--MaxDateOut between @strStartDate and @strEndDate
but I want to include the start and end dates. MaxDateOut finds the latest date in a view which groups the data.

I have also tried taking the 'and' out before the 'where' and same error.

CREATE PROCEDURE spRMU_GetChaseFiles

@strStartDate datetime,
@strEndDate datetime,
@strDepartment nvarchar(100),
@strDivision nvarchar(100)

AS

SELECT *
FROM vweChaseFilesOut

WHERE

Dept like '%'+@strDepartment+'%' and
Division like '%'+@strDivision+'%' and
where MaxDateOut >= @strStartDate and <= @strEndDate
order by MaxDateOut asc
GO




Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-03-09 : 09:40:13
Thanks - I had to change the last bit too and add MaxDateOut before the last parameter.

MaxDateOut >= @strStartDate and MaxDateOut <= @strEndDate
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-09 : 09:42:36
You can as well write:

MaxDateOut between @strStartDate and @strEndDate


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-03-09 : 10:05:38
I had that first but I wanted to include the start and end dates.
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-03-09 : 10:08:03
it should include both unless you have a time value and start and end date are equal

--------------------
keeping it simple...
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2007-03-09 : 10:32:05
Tried it again and yes, it is including start and end dates. I was getting confused.......I think it was because I was having problems with Crystal XI and its date parameters.
Go to Top of Page
   

- Advertisement -