我正在做一个Powershell,它通过循环从具有不同参数的sql查询中获取结果。问题只是循环的第一轮运行才有结果。其余所有空白结果也应该显示一些结果。
$Days = @(90,60,30,15)
$Start = 0
$End = 0
$Affiliation = 1
for ($i = 0 ; $i -lt $Affiliation.Count ; $i++) {
for ($i = 0; $i -lt $Days.Count ; $i++){
if ($Days[$i] -eq 1) {
$End = $Days[$i]
$Start = 0
write-host "Start/End r:" $Start $End
}
elseIf ($index -eq $Days.Length) {
$End = $Days[$i]
$Start = 0
write-host "Start/End m:" $Start $End
}
else {
$End = $Days[$i]
$Start = $Days[$i+1] + 1
write-host "Start/End s:" $Start $End
}
########## Queries
$Querydays = " SELECT
distinct tblcustomer.CustomerName AS Customer_Name,tblsma.sorno AS SMA_SOR_Number,FUNC_GET_JSON_VALUES('Name',tblsma.products) AS Products,DATE_FORMAT(tblsma.expiryDate,'%m/%d/%Y') AS Expiry_Date,tblsma.Remarks AS 'Remarks',DATEDIFF( DATE(tblsma.expiryDate),CURDATE()) AS Days_Left_Before_Expiration
#,GROUP_concat(tblsma.products) AS 'PRODUCT'
FROM
where
tblcustomer.affiliationID = '" + $Affiliation[$i] + "'
and tblcustomer.affiliationID <> 95
and tblaccountsgroup.GroupID <> 5
and datediff(DATE(tblsma.expiryDate),CURDATE()) between " + $Start + " and " + $End + "
order by Days_Left_Before_Expiration DESC"
#####################
$ResultDays=$null
$ResultDays = MysqlConn -Query $Querydays
Write-Host $ResultDays
$EmailBody = $EmailBody + "`r `n" + "<b>List of Valid License that will due in next " + $Days[$i] + " days:</b>"
foreach($row in $ResultDays)
{
$EmailBody = "`n" + $EmailBody + "`r `n" + "account Name : " + $row.Item(0) + "`r" +
"SOR No. : " + $row.Item(1) + "`r" +
"Product Name : " + $row.Item(2) + "`r" +
"Expiry Date : " + $row.Item(3) + "`r" +
"Remarks : " + $row.Item(4) + "`r" +
"Days Before Expiry : " + $row.Item(5) + "`r" +
"`n"
}
$rep = $Days[$i+1]
}
}
Start/End s: 61 90
System.Data.DataRow System.Data.DataRow System.Data.DataRow
Start/End s: 31 60
Start/End s: 16 30
Start/End s: 1 15