Monday, October 27, 2014

Search a file for a string and update text using powershell

"Starting"
# Put the directory where the photos are located here
$Directory = "C:\Users\jmm\Desktop\deploy"
# filename to search for
$FileName = get-childitem $Directory -recurse -Include ac360.js
# Counter for testing
#$g = 0
foreach ($file in $FileName){
$filename = $file.BaseName
$Find_This = "var maxLen = obj.maxlength;"
If (Get-Content $file | Select-String -Pattern $Find_This){
$indx = Select-String $Find_This $file | ForEach-Object {$_.LineNumber}
#array of file lines is 0 based.
$indxone = $indx - 1
"Found at line $indxone with line content " + (Get-Content $file)[$indxone]
# Need to check line previous to the line we are changing to make sure the file wasn't already changed
# since we are adding stuff after the line and not before.
$indxtwo = $indx - 2
# If it finds what it thinks it should find
If ((Get-Content $file)[$indxtwo] | select-string -Pattern "var obj = acEvent.srcElement; "){
"Found at $indxtwo " + (Get-Content $file)[$indxone] + "Changed at $indxone " + (Get-Content $file)[$indxone]
# replace the line and save it back to the same file
(get-content $file) | foreach-object {$_ -replace $Find_This, "if (typeof obj.maxLength == 'undefined'){`r`n            obj.maxLength = 4000;`r`n            }`r`n       var maxLen = obj.maxLength; "} | set-content $file
}else{
"Doesn't Qualify : " + $indxtwo + " : " + (Get-Content $file)[$indxtwo]
}
}
#$g++
}
"Done"

Tuesday, October 14, 2014

Date Conversion

,CASE
WHEN ISNUMERIC([SITE VISIT]) = 1
THEN CONVERT(SMALLDATETIME, (CAST([Site Visit] AS INT)), 101)
ELSE
CASE WHEN ISDATE([SITE VISIT]) = 1
THEN CONVERT(DATETIME, ([Site Visit]), 101)
ELSE '' END
END AS date_time

Monday, August 18, 2014

A better javascript object enumeration function (sorting, table formatting)

function COSEnumerateObjectFunctions(obj){

var emailStr = "<table>";
var objarray = new Array();
var counter = 0;

for(var propertyName in obj) {
objarray[counter] = new Array(2);
objarray[counter][0] = propertyName;
objarray[counter][1] = obj[propertyName];
counter = counter + 1;
}

objarray.sort(function(a,b){  
   return a < b ? -1 : a > b ? 1 : 0;
});

for(var i = 0; i < counter; i++) {
if(i % 3 == 0){
emailStr = emailStr + '<tr><td><u><b>' + objarray[i][0] + '</b></u></td><td><u><b>' +  objarray[i][1] + '</b></u></td></tr>';
}else{
emailStr = emailStr + '<tr><td>' + objarray[i][0] + '</td><td>' +  objarray[i][1] + '</td></tr>';
}

}

emailStr = emailStr + '</table>';
aa.sendMail("wadmin@springfieldcityhall.com","jmurgolo@springfieldcityhall.com","","enumerated object 2", emailStr);

return emailStr;
}

Wednesday, August 6, 2014

Add Identity, Change Column Types, Etc..

Alter Column
alter table [dbo].[GIS_311Registrations]
alter column [StreetNumber] varchar(MAX) null

Delete Column
alter table GIS_Primary drop column [Best Guess Vacancy Rank 3]

Add Identity
ALTER TABLE GIS_VPRVacant DROP COLUMN ID
ALTER TABLE GIS_VPRVacant ADD ID INT IDENTITY(1,1)

Insert Into
INSERT INTO Table
SELECT Something
FROM Someplace

Change Column Name
EXEC sp_rename 'GIS_Primary.City Owned Vacant', 'CtyOwnVac', 'COLUMN';

Friday, July 25, 2014

Excel Import to SQL Increase Cell Size Scan via Registry

http://forums.asp.net/t/1578417.aspx?REGEDIT+TypeGuessRows+Windows+7

I know it's been forever since your post, but I had this issue as well and found out that if you're running Windows 7 64-bit, the location has changed:
My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet\4.0\Engines\Excel

Wednesday, July 16, 2014

Rank and counting within subgroups

This was done for the inspector Report.

So this is in the select statement:

,G.[Total Number of Inspections on Permit]
,rank() over (PARTITION BY [b1_alt_id] ORDER BY COALESCE([G6ACTION].[G6_COMPL_DD],[G6ACTION].[G6_ACT_DD],G6_ACT_NUM) DESC, G6_ACT_NUM DESC) AS 'Order Number'


And here is the outer apply for the total count within a given record:

OUTER APPLY (SELECT COUNT(DISTINCT [G6_ACT_NUM]) AS 'Total Number of Inspections on Permit'
FROM [G6ACTION] g6a
WHERE g6a."SERV_PROV_CODE" = B1P."SERV_PROV_CODE"
AND g6a."B1_PER_ID1" = B1P."B1_PER_ID1"
AND g6a."B1_PER_ID2" = B1P."B1_PER_ID2"
AND g6a."B1_PER_ID3" = B1P."B1_PER_ID3" AND G6A.[REC_STATUS] = 'A' AND COALESCE(g6a.[G6_ACT_DD],g6a.[G6_COMPL_DD],'') BETWEEN @startdate
AND DATEADD(d, 1, @enddate)
and (
(ISNULL(@InspectorName, '') = '')
OR (
ISNULL([GA_FNAME], '') + CASE
WHEN ISNULL([GA_MNAME], '') = ''
THEN ' '
ELSE ' ' + [GA_MNAME] + ' '
END + ISNULL([GA_LNAME], '') = @InspectorName
)
) ) AS G

Thursday, July 10, 2014

Closed Conditions

AND ISNULL([B1PERMIT].[B1_APPL_STATUS], '') <> 'CofO Issued'
AND ISNULL([B1PERMIT].[B1_APPL_STATUS], '') <> 'Closed'

AND ISNULL(B1P1.b1_appl_status,'')  not in ('cancelled','Classified Abandon','Closed','CC Issued','Classify Abandoned','CofO Issued','Duplicate','Duplicate Record','Void')