Thursday, March 29, 2012

End Date and Beginning date in an ADP

Can anyone pleae help me, I inheited this databas which is an MDB and I have to convert it to an ADP (Sql server is the engine) and I need for my users to be able to enter a end date and a beginning date when they first open a report so they can see from the end of the month to the beginning in one report. This is Accesses code as an MDB

Code Snippet

[code]SELECT [Main Table].[IR Number], [Main Table].Date, [Main Table].Inspector, [Main Table].Area, [Main Table].Violation, [Main Table].[Violation Type], [Main Table].Loss, [Main Table].[Loss Type], [Main Table].Employee, [Main Table].Action, [Main Table].[Action Type], [Main Table].Notes
FROM [Main Table]
WHERE ((([Main Table].Date) Between [Enter the Start Date] And [Enter the End Date]))
ORDER BY [Main Table].[IR Number]

SELECT [Main Table].[IR Number], [Main Table].[Date], [Main Table].Inspector, [Main Table].Area, [Main Table].Violation, [Main Table].[Violation Type], [Main Table].Loss, [Main Table].[Loss Type], [Main Table].Employee, [Main Table].[Action], [Main Table].[Action Type], [Main Table].Notes
FROM [Main Table]
WHERE ((([Main Table].[Date] Between [Enter the Start Date] And [Enter the End Date]))
ORDER BY [IR Number]
GO

And here is SQL Servers code the only problem is that when I run this in the Query analyzer it gives me an error message that says, can anyone help me please?

"Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'Enter the Start Date'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'Enter the End Date'."

Change the [Enter the start date] placeholders to parameters (@.StartDate @.EndDate)|||

Oh thank you so much is this what you mean?

Code Snippet

SELECT [IR Number], Date, Inspector, Area, Violation, [Violation Type], Loss, [Loss Type], Employee, Action, Notes, [Action Type]
FROM dbo.[Main Table]
WHERE (Date = @.StartDate) AND (Date = @.EndDate)

|||

You can still use the BETWEEN clause

Code Snippet

SELECT [IR Number], Date, Inspector, Area, Violation, [Violation Type], Loss, [Loss Type], Employee, Action, Notes, [Action Type]
FROM dbo.[Main Table]
WHERE Date IS BETWEEN @.StartDate AND @.EndDate

|||

Whoops, the 'IS' should not be in there

Code Snippet

SELECT [IR Number], Date, Inspector, Area, Violation, [Violation Type], Loss, [Loss Type], Employee, Action, Notes, [Action Type]
FROM dbo.[Main Table]
WHERE Date BETWEEN @.StartDate AND @.EndDate

|||

BRUCE YOU ARE THE BEST THANK YOU SO MUCH YOU DONT KNOW HOW LONG I HAVE BEEN WRESTLING WITH THIS

I inherited this database and I have queries that have to be converted from an MDB to an ADP and its not easy.

thank you so much

sql

No comments:

Post a Comment