external help file | Module Name | online version | schema |
---|---|---|---|
SimplySql.Cmdlets.dll-Help.xml |
SimplySql |
2.0.0 |
Executes a Scalar query.
Invoke-SqlScalar [-ConnectionName <String>] [-Query] <String[]> [-CommandTimeout <Int32>]
[[-ParamObject] <PSObject>] [-WhatIf] [-Confirm] [<CommonParameters>]
Invoke-SqlScalar [-ConnectionName <String>] [-Query] <String[]> [-Parameters] <Hashtable>
[-CommandTimeout <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]
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.
PS C:\> Invoke-SqlScalar -Query "SELECT Count(1) FROM TABLE"
Simple Scalar query
PS C:\> Invoke-SqlQuery -Query "SELECT Count(1) FROM TABLE WHERE colb > @someDate" -Parameters @{someDate = (Get-Date)}
Simple Scalar query with parameters
PS C:\> $obj = [PSCustomObject]@{sd = (Get-date)}
PS C:\> $obj | Invoke-SqlScalar -Query "SELECT Count(1) FROM TABLE WHERE colb> @sd"
Simple Scalar query with parameters populated by object
The timeout, in seconds, for this SQL statement, defaults to the command timeout for the SqlConnection.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
User defined name for connection.
Type: String
Parameter Sets: (All)
Aliases: cn
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Parameters required by the query. Key matches the parameter name, Value is the value of the parameter.
Type: Hashtable
Parameter Sets: hashtable
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
The object that contains the parameters for the query, member names match the parameter name.
Type: PSObject
Parameter Sets: object
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
SQL statement to run.
Type: String[]
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Prompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: default
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.