JWeb Admin
asked on
Invoke-SqlCmd - file with multiple select statements doesn't finish execution
We have some SQL files that contain multiple select statements, however when I execute the file using Invoke-SqlCmd and output to a csv, its as if the script doesn't want to finish. I've even tried using datasets, however that yields the same results.
Is there a way to handle multiple select statements with PowerShell and Invoke-SqlCmd?
Here's an example of the script that I'm trying to run that stops the output after the first select statement. I can confirm that this script runs with no syntax errors inside SSMS, as well as sqlcmd:
Is there a way to handle multiple select statements with PowerShell and Invoke-SqlCmd?
Here's an example of the script that I'm trying to run that stops the output after the first select statement. I can confirm that this script runs with no syntax errors inside SSMS, as well as sqlcmd:
SELECT * FROM master.sys.databases ORDER BY database_id; SELECT DatabaseName,
[DirtyPageCount] * 8 / 1024 AS [Dirty PageMB],
[CleanPageCount] * 8 / 1024 AS [Clean PageMB] ,
([DirtyPageCount]+[CleanPageCount])* 8 / 1024 AS [Total BufferPool MB]
FROM
(SELECT
(CASE WHEN ([database_id] = 32767)
THEN N'Resource Database'
ELSE DB_NAME ([database_id]) END) AS [DatabaseName],
SUM (CASE WHEN ([is_modified] = 1)
THEN 1 ELSE 0 END) AS [DirtyPageCount],
SUM (CASE WHEN ([is_modified] = 1)
THEN 0 ELSE 1 END) AS [CleanPageCount]
FROM sys.dm_os_buffer_descriptors WITH (NOLOCK)
GROUP BY [database_id]) AS [buffers]
ORDER BY [DatabaseName] OPTION (RECOMPILE);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER