Skip to content

Invoke SqlScalar

mithrandyr edited this page Mar 22, 2018 · 2 revisions

Synopsis

Executes a Scalar query.

Description

Executes a Scalar query against the targeted connection. If the sql statement generates multiple rows and/or columns, only the first column of the first row is returned.

Parameters

Mandatory = YES|NO|<default value>

Name Type Mandatory Description
ConnectionName String "default" User defined name for the connection
Query String "default" SQL statement to run.
Parameters Hashtable Parameters required by the query. Key matches the parameter name, value is the value of the parameter.
CommandTimeout Integer -1 The timeout, in seconds, for this SQL statement, defaults (-1) to the command timeout for the SqlConnection.

Examples

Invoke-SqlScalar -Query "SELECT Count(1) FROM TABLE"

Invoke-SqlQuery -Query "SELECT Count(1) FROM TABLE WHERE colb > @someDate" -Parameters @{someDate = (Get-Date)}