andreasholmesberge
3/3/2017 - 10:49 AM

Essentials

SQL Essentials

Connect-AzureRmAccount

Import-Module AzureAutomationAuthoringToolkit

Import-Module MicrosoftPowerBIMgmt

Install-Module -Name ISEScriptAnalyzerAddOn

$smtpCred = (Get-Credential)
$ToAddress = 'joe@outlook.com'
$FromAddress = 'noreply@ef.com'
$SmtpServer = 'smtp.office365.com'
$SmtpPort = '587'
$Attachments = ''

$mailparam = @{
  To = $ToAddress
  From= $FromAddress
  Subject = 'Azure SSAS Process Alert'
  Body = 'This is an utomated email'
  SmtpServer = $SmtpServer
  Port = $SmtpPort
  Credential = $smtpCred
}

Send-MailMessage @mailparam -UseSsl
IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL DROP TABLE #TempTable
SELECT [Group], Item = 
	STUFF((SELECT ';' + Item
		FROM #Table B
		WHERE B.[Group] = A.[Group]
		FOR XML PATH ('')), 1, 1, '')
INTO #TempTable
FROM #Table A
GROUP BY [Group]
		/** Finding Columns **/
		USE Database
		SELECT COLUMN_NAME, TABLE_NAME 
		FROM INFORMATION_SCHEMA.COLUMNS 
		WHERE 1=1
			AND COLUMN_NAME LIKE '%Name%'
			--AND COLUMN_NAME LIKE '%ColName%'
			--AND TABLE_NAME LIKE '%Name%'
SELECT ID, Col1, Col2, Col3, 
    (SELECT MIN(Col) FROM (VALUES (Col1), (Col2), (Col3)) AS X(Col)) AS TheMin
FROM Table