Skip to content

Instantly share code, notes, and snippets.

@alexbevi
Created January 16, 2013 17:42
Show Gist options
  • Save alexbevi/4549104 to your computer and use it in GitHub Desktop.
Save alexbevi/4549104 to your computer and use it in GitHub Desktop.
DFS Activity Report Lists owners/portals/projects based on their status and outputs the result directly
/*
DFS Activity Report
Lists owners/portals/projects based on their status and outputs the result directly
----
Copyright (C) 2013 Astley Gilbert Limited
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
declare @portal_status int, @project_status int, @owner_status int
/*
Change the status values here to update the entire report
STATUSES
1 = Draft
2 = Active
4 = Inactive
8 = Deleted
*/
set @owner_status = 2
set @portal_status = 2
set @project_status = 2
declare owners_cur cursor for
select distinct(o.id), o.display_name
from owners o inner join sites s on s.owner_id = o.id
where s.status = @portal_status and o.status = @owner_status
order by o.display_name
open owners_cur
declare @owner_id varchar(40), @owner_name varchar(255), @portal_name varchar(255), @project_name varchar(255)
fetch next from owners_cur into @owner_id, @owner_name
while @@fetch_status = 0
begin
print @owner_name
declare portal_cur cursor for select display_name from sites where owner_id = @owner_id and status = @portal_status order by display_name
open portal_cur
fetch next from portal_cur into @portal_name
print ' PORTALS:'
while @@fetch_status = 0
begin
print ' ' + @portal_name
fetch next from portal_cur into @portal_name
end
close portal_cur
deallocate portal_cur
declare project_cur cursor for select display_name from products where owner_id = @owner_id and status = @project_status order by display_name
open project_cur
fetch next from project_cur into @project_name
print ' PROJECTS:'
while @@fetch_status = 0
begin
print ' ' + @project_name
fetch next from project_cur into @project_name
end
close project_cur
deallocate project_cur
fetch next from owners_cur into @owner_id, @owner_name
print ''
end
close owners_cur
deallocate owners_cur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment