June 29, 2016 at 2:45 pm
In t-sql 2012 listed , I want to place rows into the temp table called #UserCalendar for the current school year and the future school. The current school year has the active=1.
Here is the current sql:
declare @userID int =5
CREATE TABLE #UserCalendar (
UserID int,
DistrictID int,
SchoolID int,
CalendarID int,
EndYear varchar(100),
SchoolYear varchar(100),
Active bit,
[Type] varchar(50),
SchoolName varchar(400),
Number varchar(300),
CalendarName varchar(400),
SummerSchool bit,
CatalogID int)
insert into #UserCalendar
exec procUSERCalendar @userID
select distinct EndYear,SchoolYear, Active from #UserCalendar
where active = 1
drop table #UserCalendar
The sql above will display data that looks like:
EndYear SchoolYear Active
2016 15-16 1
I want to somehow modify the sql with a union or whatever you come up with to display the data to be:
EndYear SchoolYear Active
2016 15-16 1
2017 16-17 0
Thus would you show me what I can do to obtain the sql so I can obtain the desired results?
June 29, 2016 at 2:57 pm
Maybe remove the WHERE clause that's filtering out the inactive rows? A guess, because you haven't posted the definition of the procedure, so I have no idea what it inserts into the temp table.
Oh, and drop the DISTINCT unless there's a good and valid reason to have it there.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 29, 2016 at 3:59 pm
I want to select the active year where the value = 1. That currently is end year = 2016. I do not want any of the other columns that have value=0 except for where the EndYear = 2017.
June 29, 2016 at 4:02 pm
select EndYear, SchoolYear, Active from #UserCalendar
where (active = 1 OR EndYear = 2017)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply