Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Loop thru SQL files, second file doesnt run when results are aliased

$
0
0
I have a script that loops through *.sql files in a folder. It's OK if I do not alias the column result but will only run the first SQL file if I do use aliases.[code="plain"]#Loop through the .sql files and run themforeach ($filename in get-childitem -path $FolderPath -filter "*.sql" |sort-object) { invoke-sqlcmd –ServerInstance $SQLServer -InputFile $filename.fullname } [/code]Two files are currently in the folder. The results of ALIASES:[code="plain"]You------- Hello World[/code]The first SQL file:[code="plain"]select 'Hello World' as [You][/code]The second:[code="plain"]select 'Hello You' as [Me][/code]This is SUCCESSFUL when columns [b]not[/b] aliased:[code="plain"]Column1 ------- Hello World Hello You [/code]The first SQL file:[code="plain"]select 'Hello World'[/code]The second:[code="plain"]select 'Hello You'[/code]

Viewing all articles
Browse latest Browse all 467

Latest Images

Trending Articles



Latest Images