September 28, 2011 at 9:41 am
I have a pass through query that is like:
execute spsocialcount '[BeginDate]','[EndDAte]','[Holiday]';
I have also used:
execute spsocialcount '[forms]![f_main]![outreach_begin_date]','[forms]![f_main]![outreach_end_date]','[Holiday]'
both these say that they cannot convert varchar to date.
the stored procedure is:
USE [BtcSystem]
GO
/****** Object: StoredProcedure [dbo].[spsocialcount] Script Date: 09/28/2011 10:08:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[spsocialcount]
@BeginDate char(10),
@EndDate char(10),
@Holiday char(10)
as
SELECT tblMemberNameandAddress.LastName, tblMemberNameandAddress.FirstName, member_time.date, Count(member_time.date) AS NumberOfSocials
FROM tblMemberNameandAddress INNER JOIN member_time ON tblMemberNameandAddress.MemberNumber = member_time.member_number
WHERE member_time.date Between convert(datetime, @BeginDate) And convert(datetime, @EndDate) and member_time.time_out > '12/30/1899 16:30:0' OR member_time.date=convert(datetime,@Holiday)
GROUP BY tblMemberNameandAddress.LastName, tblMemberNameandAddress.FirstName, member_time.date
ORDER BY member_time.date;
September 28, 2011 at 9:45 am
What is the exact date string you're passing? You may have to run a profiler trace to catch this. And is there any reason your input variables can't be datetime instead of char(10)?
September 28, 2011 at 9:48 am
for now date string is 5/1/11, 5/31/11 and 5/30/11. i have made variables datetime with same error
September 28, 2011 at 9:58 am
Can you post the create table definitions for the Member_Time table?
It sounds like the member_time.date or member_time.time_out fields are not datetime fields and are probably varchar, and you have at least one record in there that can't be converted.
Try doing
select cast(date as datetime) from member_time
select cast(time_out as datetime) from member_time
I'd be willing to bet you get an error on one of those selects..
September 28, 2011 at 10:07 am
I did not get an error on either select and if i run the execute on sql side with literals it pulls data just fine
September 28, 2011 at 12:10 pm
September 28, 2011 at 1:01 pm
Thank you for all of your help. It appears that the forms!f_main!outreach_begin_date variables are not passing the value of the variable to the stored procedure. it is just passing a literal forms!f_main!outreach_begin_date to the procedure. I need to determine a way that the execute will pass the value of the variable to the stored procedure.
September 28, 2011 at 2:15 pm
I placed the following code on the button that opens the report:
Dim db As DAO.Database
Dim qdef As DAO.QueryDef
Set db = CurrentDb
Set qdef = db.QueryDefs("qrysocialcountpassthrough")
qdef.SQL = "execute spsocialcount '" & Forms!f_main!outreach_begin_date & "', '" & Forms!f_main!outreach_end_date & "', '" & InputBox("What is the holiday date?") & "'"
qdef.close
db.close
DoCmd.OpenReport "rptMemberSocialDailyCount", acViewPreview
works like a dream. Thanks for all of your help.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply