Skip to content

Latest commit

 

History

History
174 lines (134 loc) · 3.54 KB

Invoke-SqlScalar.md

File metadata and controls

174 lines (134 loc) · 3.54 KB
external help file Module Name online version schema
SimplySql.Cmdlets.dll-Help.xml
SimplySql
2.0.0

Invoke-SqlScalar

SYNOPSIS

Executes a Scalar query.

SYNTAX

object (Default)

Invoke-SqlScalar [-ConnectionName <String>] [-Query] <String[]> [-CommandTimeout <Int32>]
 [[-ParamObject] <PSObject>] [-WhatIf] [-Confirm] [<CommonParameters>]

hashtable

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

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.

EXAMPLES

Example 1

PS C:\> Invoke-SqlScalar -Query "SELECT Count(1) FROM TABLE"

Simple Scalar query

Example 2

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

Simple Scalar query with parameters

Example 3

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

PARAMETERS

-CommandTimeout

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

-ConnectionName

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

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

-ParamObject

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

-Query

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

-Confirm

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

-WhatIf

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

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

System.String

System.Management.Automation.PSObject

OUTPUTS

System.Object

NOTES

RELATED LINKS