2
我有一個將運行sql查詢的腳本,如果結果返回,將這些結果導出到csv文件。我現在需要更進一步,並且有類似的東西: - 運行查詢1,如果它返回結果保存。運行查詢2,如果它返回結果保存,運行查詢3,如果它返回結果保存。運行多個查詢並導出到不同的CSV文件
$server = "Main"
$database = "hellfire"
$query1 = "Select * from mousetrap"
$query2 = "Select * from mickey"
$query3 = "Select * from brimstone"
$templatefile = @"C:\book1.csv"
$savedirectory = @"C:\ExportedFromSQL\Results\"
#Actual Conenction To SQL Server Goes here
#for brevity I am omitting
#check if query returned results
if ($SqlAdapter.Fill($DataSet) - ge 1)
{
#this is where my catch comes in
#if $query1 was executed I want to save the file as mouse
#if $query2 was executed I want to save the file as mi
#if $query3 was executed I want to save the file as stone
#$DataSet.Tables[0] | Export-Csv $templatefile -NoTypeInformation
}
你如何決定運行哪個查詢? –
@AnsgarWiechers - 只要正確的查詢與正確的文件名相關聯,它們就可以以任何順序運行。 – MasterOfStupidQuestions
讓我重複這個問題:你如何決定運行哪個查詢? –