Use a Variable in Select statement

  • Ok.. Here is what I have:

    I am using: foreach ($SqlServer in get-content "F:\Powershell_Apps\Zero_Data_Tables\SQL_Servers.txt")

    To get all of my Sql Servers that I need to search each database..

    My connection is: $con = "server=$SqlServer;database=DBName;Integrated Security=sspi"

    My query is: $SqlQuery = "select $SqlServer,DatabaseName,TableName,Rows from Zero_Data_Tables"

    But it is not liking the $SqlServer so if I take it out it works fine...

    Any suggestions...

  • I found a solution...

    $SqlQuery = "select " + $SqlServer + ",DatabaseName,TableName,Rows from Zero_Data_Tables"

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply