Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Invoke-Sqlcmd - Server $Server -Query 'SELECT Column FROM Database'
- Column
- ------
- 1
- 2
- 3
- 4
- 5
- #Powershell takes the above results applies single quotes around the row value, adds a comma, then puts the next value in single quotes #on the same line and adds a comma, so on until the last value which gets no trailing comma.
- Invoke-Sqlcmd -Server $Server -Query 'SELECT Column2 , Column3 FROM Database2
- WHERE Column3 IN ( '1','2','3','4','5' )
- Things i've tried after a bit of reading.
- $Result = Invoke-Sqlcmd -Server $Server -Query 'SELECT Column FROM Database;'
- foreach($item in $Result){
- $item= "'"+$Result.Name+"'" }
- Write-Host $item
- Results:
- '1 2 3 4 5'
- Another I tried:
- $GetIDs = Invoke-Sqlcmd -Server Server -Query 'select column from database;'
- $SeperatedIDs = $GetIDs -join ','
- write-host = $SeperatedIDs
- Results:
- ColumnName,ColumnName,ColumnName,etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement