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

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

create procedure {databaseOwner}{objectQualifier}usp_naDevEventsGetAllBookingsGroupedByDate
(
 @moduleId int,
 @startDate datetime,
 @endDate datetime
)

as

set nocount on
  
	select e.eventName,b.eventStartDate,b.eventEndDate,e.eventId from {databaseOwner}[{objectQualifier}tblNaDevEventsUsersSignedUpToEvent] as b
	inner join {databaseOwner}[{objectQualifier}tblNaDevEvents] as e
	on e.eventId = b.eventId
	where paymentStatusId = 1 and b.moduleId =@moduleId
	and b.eventStartDate >= @startDate and b.eventStartDate <= @endDate
	group by e.eventName,b.eventStartDate,b.eventEndDate,e.eventId
	order by eventName,b.eventStartDate

GO

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

--product image table

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEventImages](
	[ImageId] [int] IDENTITY(1,1) NOT NULL,
	[EventId] [int] NOT NULL,
	[ImageUrl] [nvarchar](500) NOT NULL,
	[Caption] [nvarchar](1000) NULL,
	[DisplayOrder] [int] NOT NULL,
 CONSTRAINT [PK_{objectQualifier}tblNaDevEventImages] PRIMARY KEY CLUSTERED 
(
	[ImageId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF)
)

GO

ALTER TABLE {databaseOwner}[{objectQualifier}tblNaDevEventImages]  WITH CHECK ADD  CONSTRAINT [FK_{objectQualifier}tblNaDevEventImages_tblNaDevEvents] FOREIGN KEY([eventId])
REFERENCES {databaseOwner}[{objectQualifier}tblNaDevEvents] ([eventId])
ON DELETE CASCADE
GO

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

create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventImages_AddImage]
(
 @eventId int,
 @ImageUrl nvarchar(500),
 @caption nvarchar(1000) = null,
 @displayOrder int
)

as

	insert into {databaseOwner}[{objectQualifier}tblNaDevEventImages](EventId, ImageUrl, Caption, DisplayOrder)
			values(@eventId, @ImageUrl, @caption, @displayOrder)

return @@identity

GO

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

create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventImages_DeleteImage]
(
 @ImageId int
)

as

	delete {databaseOwner}[{objectQualifier}tblNaDevEventImages] where imageId = @ImageId

return

GO

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


create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventImages_UpdateImage]
(
 @imageId int,
 @eventId int,
 @ImageUrl nvarchar(500),
 @caption nvarchar(1000) = null,
 @displayOrder int
)

as

	update {databaseOwner}[{objectQualifier}tblNaDevEventImages] set eventId = @eventId,
																		ImageUrl = @ImageUrl,
																		Caption = @caption,
																		DisplayOrder = @displayOrder
														where ImageId = @imageId

return

GO

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

create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventImages_GetImages]
(
 @eventId int
)

as

	select * from {databaseOwner}[{objectQualifier}tblNaDevEventImages] 
		where eventId = @eventId
			order by DisplayOrder asc

return

GO

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

create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventImages_GetImage]
(
 @imageId int
)

as

	select * from {databaseOwner}[{objectQualifier}tblNaDevEventImages] 
		where ImageId = @imageId

return

GO


GO
