Search This Blog & Web

Thursday, July 21, 2011

Insert Data from procedure Output



Sample Code:

CREATE TABLE #RecurrenceEventData (EventID int,StartDate datetime, StartTime varchar(8), EndDate datetime, EndTime varchar(8))


INSERT #RecurrenceEventData EXEC Get_Recurrence_Events 4,@CityID,@CategoryID,@Keyword,@Neighborhood,@Sort,@FromDate,@ToDate



Output from Get_Recurrence_Events procedure will be saved in #RecurrenceEventData 


Create PROCEDURE [dbo].[Get_RecurrenceEvents]
@FromDate datetime = NULL,
@ToDate datetime = NULL
AS
BEGIN

CREATE TABLE #RecurrenceEvent(EventID int,StartDate datetime,StartTime varchar(8),EndDate datetime,EndTime varchar(8));

SET @NewDate = GETDATE();

INSERT INTO #RecurrenceEvent
SELECT  
Events.EventID, EventDates.Date,RecurrenceInfo.StartTime,RecurrenceInfo.EndDate 
FROM 
Events 
Where (CONVERT(CHAR(10),EventDates.Date ,120) BETWEEN CONVERT(CHAR(10),@FromDate ,120) AND CONVERT(CHAR(10),@ToDate ,120))

SELECT * FROM #RecurrenceEvent
    DROP TABLE #RecurrenceEvent
END

No comments: