Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...Conditionalize a DNN Stored ProcedureConditionalize a DNN Stored Procedure
Previous
 
Next
New Post
5/1/2012 3:42 PM
 

I am using the Events module and  I want to customize one of the stored procedures Basically what I am after is:

IF
E.ModuleId = '618'
THEN select date between '2012-01-01' AND '2012-12-31'
ELSE run it as written

I've tried numerous things and just don't think I have a good enough grasp of SQL to get this figured out on my own. So I come to the gurus to see if you can help me out.

Thanks for any help you can offer. Let me know if you need a better explanation or more details. You can see the background on this issue here

The current spoc is:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO


/*** EventsGetByRange ***/

ALTER PROCEDURE [dbo].[EventsGetByRange]
(
 @Filter nvarchar(500),
 @BeginDate datetime,
 @EndDate datetime
)
AS
SET DATEFORMAT mdy
Declare @sql nvarchar(4000)

Select @sql = 'SELECT E.PortalID, E.EventID, E.RecurMasterID, E.ModuleID, E.EventDateBegin, E.EventDateEnd, '
 + 'E.EventTimeBegin, E.Duration, E.EventName, E.EventDesc, '
 + 'E.Importance, E.CreatedDate,  '
 + 'CreatedBy = U.DisplayName, '
 + 'CreatorID =  E.CreatedBy, '
 + 'E.Every, '
 + 'E.Period, '
 + 'E.RepeatType, '
 + 'E.Notify, '
 + 'E.approved, '
 + 'E.Signups, '
 + 'E.MaxEnrollment, '
 + '(Select count(*) from dbo.EventsSignups WHERE EventID = E.EventID and E.Signups = 1) as Enrolled, '
 + 'E.EnrollRoleID, '
 + 'E.EnrollFee, '
 + 'E.EnrollType, '
 + 'E.PayPalAccount, '
 + 'E.PayPalPassword, '
 + 'E.Cancelled, '
 + 'E.DetailPage, '
 + 'E.DetailNewWin, '
 + 'E.DetailURL, '
 + 'E.ImageURL, '
 + 'E.ImageType, '
 + 'E.ImageWidth, '
 + 'E.ImageHeight, '
 + 'E.ImageDisplay, '
 + 'E.Location, '
 + 'c.LocationName, '
 + 'c.MapURL, '
 + 'E.Category, '
 + 'b.CategoryName, '
 + 'b.Color, '
 + 'b.FontColor, '
 + 'E.Reminder, '
 + 'E.TimezoneOffset, '
 + 'E.SendReminder, '
 + 'E.ReminderTime, '
 + 'E.ReminderTimeMeasurement, '
 + 'E.ReminderFrom, '
 + 'E.SearchSubmitted, '
 + 'E.CustomField1, '
 + 'E.CustomField2, '
 + 'E.EnrollListView, '
 + 'E.DisplayEndDate, '
 + 'E.AllDayEvent, '
 + 'E.OwnerID, '
 + 'OwnerName = O.DisplayName, '
 + 'E.LastUpdatedAt, '
 + 'LastUpdatedBy = L.DisplayName, '
 + 'E.LastUpdatedID, '
 + '(Select ModuleTitle from dbo.Modules WHERE ModuleID = E.ModuleID) as ModuleTitle, '
 + 'RMOwnerID = r.OwnerID, '
 + 'r.RRULE, '
 + 'E.OriginalDateBegin, '
 + 'E.NewEventEmailSent '
 + 'FROM dbo.Events E '
 + 'inner join dbo.EventsRecurMaster AS r on E.RecurMasterID = r.RecurMasterID '
 + 'left outer join dbo.Users U on E.CreatedBy = U.UserID '
 + 'left outer join dbo.Users O on E.OwnerID = O.UserID '
 + 'left outer join dbo.Users L on E.LastUpdatedID = L.UserID '
 + 'left join dbo.EventsCategory b on E.Category = b.Category '
 + 'left join dbo.EventsLocation c on E.Location = c.Location '
 + 'WHERE ((E.EventTimeBegin <= DATEADD(DAY,1,''' + convert(varchar, @EndDate) + ''') AND DATEADD(minute,E.Duration,E.EventTimeBegin) >= ''' + convert(varchar, @BeginDate) + ''') OR '
 + '  (E.EventTimeBegin BETWEEN ''' + convert(varchar, @BeginDate) + ''' AND DATEADD(DAY,1,''' + convert(varchar, @EndDate) + ''')))'
 + '  AND E.Approved = 1'
 + '  AND E.Cancelled = 0'
 + ' ' + @Filter + ' '
 + ' ORDER BY E.EventDateBegin, E.EventTimeBegin, E.EventDateEnd'
EXEC (@sql)

 
New Post
6/19/2012 10:55 PM
 

Totally untested, but I'd try something like this in the where clause.

+ 'WHERE Case E.ModuleID
 + '       When 618 Then
 + '         ((E.EventTimeBegin <= DATEADD(DAY,1,''' + convert(varchar, '2012-12-31') + ''') AND DATEADD(minute,E.Duration,E.EventTimeBegin) >= ''' + convert(varchar, '2012-01-01') + ''') OR '
 + '         (E.EventTimeBegin BETWEEN ''' + convert(varchar, '2012-01-01') + ''' AND DATEADD(DAY,1,''' + convert(varchar, '2012-12-31') + ''')))'
 + '       Else
 + '         ((E.EventTimeBegin <= DATEADD(DAY,1,''' + convert(varchar, @EndDate) + ''') AND DATEADD(minute,E.Duration,E.EventTimeBegin) >= ''' + convert(varchar, @BeginDate) + ''') OR '
 + '         (E.EventTimeBegin BETWEEN ''' + convert(varchar, @BeginDate) + ''' AND DATEADD(DAY,1,''' + convert(varchar, @EndDate) + ''')))'
 + '       End
 + '  AND E.Approved = 1'
 + '  AND E.Cancelled = 0'
 + ' ' + @Filter + ' '
 + ' ORDER BY E.EventDateBegin, E.EventTimeBegin, E.EventDateEnd'

Not going to advise caution in this endeavor. But caution would be advisable even without such advice.


pmgerholdt
 
Previous
 
Next
HomeHomeDevelopment and...Development and...SQL and SQL Ser...SQL and SQL Ser...Conditionalize a DNN Stored ProcedureConditionalize a DNN Stored Procedure


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out