
-- SQLAzureMWParseTSQL TSQL Output File:
-- Generated at: 3/1/2014 3:07:20 PM

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}tblNaDevEvents]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table {databaseOwner}[{objectQualifier}tblNaDevEvents]
GO

CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEvents] (
	[eventId] [int] IDENTITY (1, 1) NOT NULL ,
	[eventName] [nvarchar](4000)NOT NULL,
	[description] [ntext] not null,
	[eventStartDate] [datetime] not null,
	[eventEndDate] [datetime] not null
    constraint [PK_{objectQualifier}tblNaDevEvents] primary key clustered
	(
		[eventId] asc
	)
)
GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_insertUpdateEvent]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_insertUpdateEvent
GO

create procedure {databaseOwner}{objectQualifier}usp_insertUpdateEvent
(
 @eventId int,
 @eventName nvarchar(4000),
 @description ntext,
 @eventStartDate dateTime,
 @eventEndDate dateTime
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEvents] where eventId = @eventId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEvents] set   eventName = @eventName,
																	  description = @description,
																	  eventStartDate = @eventStartDate,
																	  eventEndDate = @eventEndDate																 												 
									 
																	  where eventId = @eventId
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEvents] (eventName,description,eventStartDate,eventEndDate)

	values (@eventName,@description,@eventStartDate,@eventEndDate)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_deleteEventByEventId]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_deleteEventByEventId
GO

create procedure {databaseOwner}{objectQualifier}usp_deleteEventByEventId
(
 @eventId int
)

as

set nocount on
  
	delete from {databaseOwner}[{objectQualifier}tblNaDevEvents] where eventId = @eventId
GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_getEventByEventId]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_getEventByEventId
GO

create procedure {databaseOwner}{objectQualifier}usp_getEventByEventId
(
 @eventId int
)

as

set nocount on
  
	select * from {databaseOwner}[{objectQualifier}tblNaDevEvents] where eventId = @eventId
GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_getAllEvents]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_getAllEvents
GO

create procedure {databaseOwner}{objectQualifier}usp_getAllEvents

as

set nocount on
  
	select * from {databaseOwner}[{objectQualifier}tblNaDevEvents] order by eventStartDate desc
GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_getAllEventsByStartAndEndDate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_getAllEventsByStartAndEndDate
GO

create procedure {databaseOwner}{objectQualifier}usp_getAllEventsByStartAndEndDate
(
 @startDate datetime,
 @endDate datetime
)

as

set nocount on
  
	select * from {databaseOwner}[{objectQualifier}tblNaDevEvents] where eventStartDate >= @startDate and eventStartDate <= @endDate
	order by eventStartDate desc
GO
