You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done.
# See also a good hint with explanation between like and contains:
# http://windowsitpro.com/blog/powershell-contains
$fullstring = "This is my string";
if ($fullstring -like "*my*")
{
Write-Host "found" -ForegroundColor Green;
}
else
{
Write-Host "nope" -ForegroundColor Red;
}
234
PowerShell
Datum, Zeit
Aktuelles Datum/Uhrzeit
$myDate=Get-Date -format "yyyy-MM-dd hh:mm";
write-host $myDate -Foregroundcolor Cyan;
# 2014-01-14 10:15 # Maybe AM or PM
# For 24h Version
$myDate=Get-Date -format "yyyy-MM-dd HH:mm";
write-host $myDate -Foregroundcolor Cyan;
# 2014-01-14 22:15
248
PowerShell
Fallunterscheidung
Ternary operator
## Example from here: https://www.kongsli.net/2012/02/23/powershell-another-alternative-to-ternary-operator/
$thisVar='OK'
$resultVar = @{$true=1;$false=2}[$thisVar -eq 'OK']
// same as if-else construction
if ($thisVar -eq 'OK')
{
$resultVar = 1;
}
else
{
$resultVar = 2;
}
-- Sollte die Zieltabelle (myDestinationTable) bereits vorhanden sein
-- wird diese überschrieben (neue Strukturen werden übernommen)
SELECT
*
INTO myDestinationTable
FROM mySourceTable
272
MS Access SQL
Datenbank
NULL Wert eines Feldes übersteuern
SELECT
FieldA
,Nz([FieldB,"This field is null") As FieldB_Nz
FROM TableA
266
MS Access VBA
Array
Dictionary Basics
' empty dict
Dim myDict As Dictionary
Set myDict = New Dictionary
' some static values
myDict.Add "key1", "value1"
myDict.Add "key2", "valueY"
myDict.Add "keyX", "value98"
' update a key programmatically
myDict.Remove "key1"
myDict.Add "key1", "new value"
' iterate
Dim strKey As Variant
Dim current_key As String
Dim strValue As String
For Each strKey In myDict.Keys()
current_key = strKey
strValue = myDict.Keys(strKey)
Next
' Exists
If myDict.Exists(strKey) Then
Debug.Print "yes"
End If
' get an specific item
Dim subdict As String
subdict = myDict.Keys("key2")
# valueY
283
Yii2
Datenbank
Verzeichnis erstellen
<?php
// Example as SQL:
// SELECT * FROM MainTable
// WHERE fieldA=5 AND fieldB IN (SELECT id FROM SubTable WHERE fieldC=551)
$fieldC = 551;
$SubTable_idQry = SubTable::find()->select('id')->where(['fieldC' => $fieldC]);
// Static way:
$fieldA = 5;
// As result:
$fieldA = ThirdTable::find()
->select('fieldA_Reference')
->where(['fieldC' => $fieldC])
->one();
$MainTableResultQry = MainTable::find()
->where(['in', 'fieldB', $SubTable_idQry])
->andWhere(['fieldA' => $fieldA])
->all();
?>
284
Yii2
Datenbank
Abfrage mit Aggregration
<?php
/* // Example as SQL
SELECT
FieldA
,COUNT(FieldA) as cnt
FROM MainTable
WHERE FieldA = 5
GROUP BY FieldA
*/
$MainTableResultQry = MainTable::find()
->select(['FieldA', 'COUNT(FieldA) as cnt'])
->where(['FieldA' => 5])
->groupBy(['FieldA'])
->createCommand()
->queryAll();
?>