![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | how to get "select @@version" to display one long string Hi, I have a script which gets the SQLServer version but it comes back with a string and 3 linefeeds. Can someone help me put this into one long string? Here is the script: $conn = new-object System.Data.SqlClient.SqlConnection $conn.ConnectionString = "server=testsvr;integrated security=sspi;database=master" $conn.Open() $cmd = new-object System.Data.SqlClient.SqlCommand $cmd.CommandText="SELECT @@VERSION as version" $cmd.Connection=$conn $rdr = $cmd.ExecuteReader() While($rdr.Read()){ Write-Host "version: $($rdr['version'])" } Output: version: Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) Mar 23 2007 16:28:52 Copyright (c) 1988-2005 Microsoft Corporation Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2) |
My System Specs![]() |
| | #2 (permalink) |
| | RE: how to get "select @@version" to display one long string There's probably a better way to do this, but at the end of the script you could do: # instead of Write-Host, just capture the result While($rdr.Read()){ $verionsString = "version: $($rdr['version'])" } # and # replace newlines and then replace extra spaces $versionString -replace "`n"," " -replace "[\s][\s]*"," " "Frank" wrote: > Hi, > > I have a script which gets the SQLServer version but it comes back with a > string and 3 linefeeds. Can someone help me put this into one long string? > Here is the script: > > $conn = new-object System.Data.SqlClient.SqlConnection > $conn.ConnectionString = "server=testsvr;integrated > security=sspi;database=master" > $conn.Open() > $cmd = new-object System.Data.SqlClient.SqlCommand > $cmd.CommandText="SELECT @@VERSION as version" > > $cmd.Connection=$conn > $rdr = $cmd.ExecuteReader() > > While($rdr.Read()){ > Write-Host "version: $($rdr['version'])" > } > > Output: > > version: Microsoft SQL Server 2005 - 9.00.3054.00 (Intel X86) > Mar 23 2007 16:28:52 > Copyright (c) 1988-2005 Microsoft Corporation > Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| wscript.echo only a new line / embed a "CR" in a text string ? | VB Script | |||
| do not display "ERRORS" when running script without using $erroractionpreference = "SilentlyContinue" | PowerShell | |||
| "select Name,Path from Win32_Share" permissions required by ASP.NET to return paths, | Vista security | |||
| "string STR_ERR_OS was not found in string table" | Vista installation & setup | |||
| Windows Vista "international" or "North America" version?! | Vista General | |||