Group

MSSQL combine SUMS from 2 tables

Below query combines the SUMS of two tables into a total SUM for a specific column.

WITH combiTable ([Table], xName, xValue)
AS ( SELECT 1 AS [Table], name, SUM(value) FROM Table1 GROUP BY name
     UNION
     SELECT 2 AS [Table], name, SUM(value) FROM Table2 GROUP BY name )
SELECT xName AS Name, SUM(xValue) AS Total FROM combiTable
GROUP BY xName
ORDER BY Total DESC
GO

MSCLUSTER 2008 Cluster Commandline

Display cluster resources.

cluster [group | res]
PS> [Get-ClusterGroup | Get-ClusterResource] -Cluster "<CLUSTERNAME>"
PS> Get-ClusterGroup -Cluster "<CLUSTERNAME>" | Where-Object { $_.OwnerNode -eq "<CLUSTERNODE>" } | SELECT Name

Move a cluster group to a different node.

cluster group "Cluster Group" /moveto:<NODENAME>
PS>  Move-ClusterGroup -Name "Cluster Group" -Cluster "<CLUSTERNAME>" -Node "<CLUSTERNODE>"

Display all registered nodes for a resource.

cluster res "SQL Network Name (NETWORKNAME)" /listowners
PS> Get-ClusterOwnerNode -Cluster "<CLUSTERNAME>" -Resource "<CLUSTERRESOURCE>

Bring cluster group online…

PS> Start-ClusterGroup -Name "<CLUSTERGROUPNAME>"

Switch a AlwaysOn Group to a secondary replica…

Switch-SqlAvailabilityGroup -Path SQLSERVER:\SQL\[SERVER]\[INSTANCE]|DEFAULT\AvailabilityGroups\[AOGROUP]

Change witness fileshare on a NodeAndFileMajority cluster. First change to NodeMajority and then back to NodeAndFileMajority using the new fileshare.

PS> Set-ClusterQuorum -NodeMajority
PS> Set-ClusterQuorum -NodeAndFileShareMajority \\server\fswitness$\clustername