Skip to content

Instantly share code, notes, and snippets.

View othtim's full-sized avatar

Tim Scott othtim

  • Edmonton, Alberta, Canada
View GitHub Profile
@othtim
othtim / bestofRandomizer.sql
Created March 31, 2014 23:30
"Best Of" request randomizer
/*
Trying to randomize the records in dbo.BestOfRequestDetail, but preserve them in sets of 10 by iBestOfRequestID.
*/
--clean up overall
if object_id('tempdb..#newresults') is not null
drop table #newresults;
if object_id('tempdb..#finalresults') is not null
drop table #finalresults;
@othtim
othtim / sino_conversion.sql
Created March 31, 2014 23:28
conversion scripts for Sino
begin transaction
delete from contact
--cstreet is too small
alter table location alter column cstreet varchar(70)
@othtim
othtim / trailingBlankChecker.sql
Last active August 29, 2015 13:57
Check the database for fields with trailing blanks
drop table #temptable
select sObj.name as cTable, sCol.name as cColumn
into #temptable
from sys.tables sTable
inner join sys.columns sCol
on sCol.object_id = sTable.object_id
inner join sys.objects sObj
on sCol.object_id = sObj.object_id
inner join sys.types sType
@othtim
othtim / contact_reimport.sql
Last active August 29, 2015 13:57
Trinity / RENWEB conversion
drop table #contactrelation
drop table #contact
drop table #location
declare @ischoolid int
set @ischoolid = 1
@othtim
othtim / fixCourseClassGovLWCA.sql
Created March 31, 2014 23:15
Various fixes for course/class tables - LWCA
------------------------------------------------------------------------------------
--first term
update Class
set iLV_SessionID = 258
where iclassid in
(select iclassid from Class
@othtim
othtim / LSSDreport.sql
Created March 31, 2014 23:14
LSSD Daily Attendance Report
select
--s.clastname as 'lastname',
--s.cfirstname as 'firstname',
s.clastname + ', ' + s.cFirstName + ' (' + ltrim(rtrim(cast(s.istudentid as CHAR))) + ')' as [combinedname],
dbo.getgradesname(s.igradesid) as [grade],
h.cName as [homeroom],
l.cphone as [phone],
--a.iClassID as [class],
--a.ddate as [date],
( select COUNT(*) from Attendance att
@othtim
othtim / parklandlocationlinker.sql
Created March 31, 2014 23:13
parkland (and generic) location linker
--function to trim street info
IF object_id(N'fn_doStuff', N'FN') IS NOT NULL
DROP FUNCTION fn_doStuff
GO
CREATE FUNCTION fn_doStuff
( @value nvarchar(500) )
@othtim
othtim / fixcourseobjectives.sql
Created March 31, 2014 23:11
livingsky - fixcourseobjectives
update Settings set cValue='N' where cKey like 'LDAP/Login'
--begin transaction
declare @icourseObjectiveID int
declare @csubject varchar(500)
declare @mnotes varchar(500)
@othtim
othtim / mCompareNonOwnershipFields.sql
Created March 31, 2014 23:09
post-migration database compare - needs to be redone from scratch
use eastcentral
SET NOCOUNT ON
GO
@othtim
othtim / PVbusplanner
Last active August 29, 2015 13:57
Prairie Valley bus planner export
declare @command varchar(1000)
IF OBJECT_ID('tempdb..#temptable') IS NOT NULL DROP TABLE #temptable
select distinct
S.cStudentNumber,
s.cGovernmentNumber as 'Government Number',
s.cLegalLastName as 'Legal Last Name',
s.cLegalFirstName as 'Legal First Name',
us.UF_1590,