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
让我重复这个问题:你如何决定运行哪个查询? –