Link to home
Start Free TrialLog in
Avatar of jerseyguy29
jerseyguy29

asked on

Can someone convert these 3 stored procedures into 3 plain old SQL statements?

create procedure GetSchedule (@nMonth tinyint, @nYear smallint)
as
   select idSchedule, convert(varchar, datepart(dd, dtDate)) 'nDay', vcEvent
   from Schedule
   where datepart(yy, dtDate) = @nYear and datepart(mm, dtDate) = @nMonth
   order by datepart(dd, dtDate)
go

create procedure AddEvent (@vcDate varchar(20), @vcEvent varchar(100))
as
   insert Schedule
   select @vcDate, @vcEvent
go

create procedure DeleteEvent (@idSchedule smallint)
as
   delete Schedule where idSchedule = @idSchedule
go
Avatar of Sharper
Sharper

declare
     @nMonth tinyint,
     @nYear smallint

set @nMonth = ??
set @nYear = ??

select
     idSchedule,
     convert(varchar, datepart(dd, dtDate)) 'nDay',
     vcEvent
from
     Schedule
where
     datepart(yy, dtDate) = @nYear
     and datepart(mm, dtDate) = @nMonth
order by datepart(dd, dtDate)
go

declare
     @vcDate varchar(20),
     @vcEvent varchar(100))

set @vcDate = ??
set @vcEvent = ??

insert
     Schedule
select
     @vcDate,
     @vcEvent
go

declare
     @idSchedule smallint

set @idSchedule = ??

delete
     Schedule
where
     idSchedule = @idSchedule
go
Avatar of jerseyguy29

ASKER

I'm not sure if I understand.  What I am talking about is to convert the stored procedures I pasted into SQL queries so I can query my Access database.  I am not using SQL Server.
ASKER CERTIFIED SOLUTION
Avatar of Sharper
Sharper

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brendt Hess
Access?  Try:

SELECT idSchedule, datepart("d", dtDate), vcEvent
  FROM Schedule
  WHERE datepart("y", dtDate) = [Enter Year] and datepart("m", dtDate) = [Enter Month]
  order by dtDate



INSERT INTO Schedule
  VALUES ([Enter Date Text], [Enter Event Text]


DELETE FROM Schedule
WHERE idSchedule = [Enter Schedule ID to Delete]
then why didnt you post this question under access
Here is the table information;

table name = "Schedule"
(
   idSchedule   primary key,
   dtDate      smalldatetime not null,
   vcEvent      text(100) not null
)

I just tried Sharper's SQL answer and it came up with the following error.  Do you know why this error is occurring?

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'convert(varchar, datepart(dd, dtDate)) 'nDay''.

/cad/calendar.asp, line 25

I also tried bhess's answer but it came up with the following error.

Microsoft VBScript compilation error '800a03ee'

Expected ')'

/cad/calendar.asp, line 25

Set rs = dbConn.Execute ("SELECT idSchedule, datepart("d", dtDate), vcEvent FROM Schedule WHERE datepart("y", dtDate) = [Enter Year] and datepart("m", dtDate) = [Enter Month] order by dtDate" & nMonth & ", " & nYear)

 
Anybody have any more ideas?
For mine to work, you must embed the double-quotes in the string by doubling them up, e.g.:

Set rs = dbConn.Execute ("SELECT idSchedule, datepart(""d"", dtDate), vcEvent FROM Schedule WHERE datepart(""y"", dtDate) = [Enter Year] and datepart(""m"", dtDate) = [Enter Month] order by dtDate" & nMonth & ", " & nYear)

For Sharper's to work, you need to change the conversions to Access syntax (which is what mine uses)