我正在使用以下select语句从excel中提取数据并将其放入数据表中。那里有一个坏行,我不想接,所以这部分[Plan] <>'PLAN_BO'但是它不适用于其他两个OR语句。 [计划]应该是日期时间列,但有一行额外的文字。
[Plan] <>'PLAN_BO'或[Plan]的组合在一起无效,但三个组合在一起无效。
comm.CommandText = "Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Doc Avail], [Plan] from [ca_rpt$] where [Plan] <> 'PLAN_BO' or [Plan] is null or [Plan] >= DATE() order by Category, [Project ID], Package, [Design ID], LLW";
有没有一种方法可以偏移第一行,因为那是坏行,但不是行标题。我在语句末尾尝试了“偏移1行”,但是它没有用。
编辑:当前状况
(ISDATE([Bid Open Plan]和[Bid Open Plan]> = DATE())或[Bid Open Plan]为空
[开标计划]> = DATE()被忽略。
using (OleDbConnection conn = new OleDbConnection())
{
System.Data.DataTable dt = new System.Data.DataTable();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'";
using (OleDbCommand comm = new OleDbCommand())
{
comm.CommandText = "Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Pkg#], [Doc Available], [Bid Open Plan] from(Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Pkg#], [Doc Available], [Bid Open Plan] from [ca_rpt$] where ISDATE([Bid Open Plan]) or [Bid Open Plan] is null) Where [Bid Open Plan] >= DATE() order by Mincat, Minse, [Pkg#], [Project ID], Package, [Design ID], LLW";
comm.Connection = conn;
using (OleDbDataAdapter da = new OleDbDataAdapter())
{
da.SelectCommand = comm;
da.Fill(dt);
答案 0 :(得分:1)
可能您需要检查列值是否为有效日期。您可以使用ISDATE
来检查值是否为有效日期,并仅返回有效日期。
Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School,
[Project Description], [Doc Avail], [Bid Open Plan]
FROM(
Select Category, [Project ID], Package, [Design ID], LLW, Bldg, School, [Project Description], [Doc Avail], [Bid Open Plan]
from [ca_rpt$]
where ISDATE([Bid Open Plan]) =1 or [Bid Open Plan] is null
)
WHERE [Bid Open Plan]>=Date()
order by Category, [Project ID], Package, [Design ID], LLW