Synopsis

Invokes a sql statement intended to return only a single value.

Syntax

Invoke-SqlScalar [-Query] <String> [[-Parameters] <Hashtable>] [-ConnectionName <String>] [-CommandTimeout <Int32>] [<CommonParameters>]

Description

Invokes a sql statement intended to return only a single value. If the sql statement generates multiple rows and/or columns, only the first column of the first row is returned.

Parameters

-Query <String>

SQL statement to run.

Required? True
Position? 1
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-Parameters <Hashtable>

Parameters required by the query. Key matches the parameter name, Value is the value of the parameter.

Required? False
Position? 2
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-ConnectionName <String>

User defined name for connection.

Required? False
Position? named
Default value Default
Accept pipeline input? false
Accept wildcard characters? False

-CommandTimeout <Int32>

The timeout for this SQL statement, defaults to the command timeout for the SqlConnection.

Required? False
Position? named
Default value -1
Accept pipeline input? false
Accept wildcard characters? False

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

Examples

Example 1

PS C:\> Invoke-SqlScalar -Query "Select GetDate()"
Friday, June 19, 2015 12:12:36 AM

Invokes a sql statement returning a single value.

Last edited Jun 23, 2015 at 2:29 PM by mastertook, version 3