讨教各位大大,本人的查询出错。 where COMBOBOX1.TEXT 哪里出问题了?应该是引号问题,具体是引号怎么用啊
string strSQL = @”Select ROW_NUMBER() OVER (ORDER BY 船公司 DESC) AS 序号,日期,船公司,英文船名,中文船名,航次,进出口,SUM(e20) e20, SUM(e40) e40, SUM(e45) e45, SUM(f20) f20, SUM(f40) f40, SUM(f45) f45,sum(teu) 合计teu
from
(
select CONVERT(VARCHAR, CAST(b.enddate AS DATE), 111) AS 日期, b.WEIGHT as 船公司, b.shipname as 英文船名, b.cshipname as 中文船名, b.voyage as 航次, b.ieflag as 进出口,
CASE WHEN(a.ewflag = “E” AND a.ssize = “20”)THEN 1 ELSE 0 END AS e20,
CASE WHEN(a.ewflag = “E” AND a.ssize = “40”)THEN 1 ELSE 0 END AS e40,
CASE WHEN(a.ewflag = “E” AND a.ssize = “45”)THEN 1 ELSE 0 END AS e45,
CASE WHEN(a.ewflag = “F” AND a.ssize = “20”)THEN 1 ELSE 0 END AS f20,
CASE WHEN(a.ewflag = “F” AND a.ssize = “40”)THEN 1 ELSE 0 END AS f40,
CASE WHEN(a.ewflag = “F” AND a.ssize = “45”)THEN 1 ELSE 0 END AS f45,
case a.ssize WHEN “45” THEN 2.25 WHEN “40” THEN 2 WHEN “20” THEN 1 ELSE 2.25 END AS teu
FROM container a
left join ships b ON(A.SHIPNAME = B.SHIPNAME AND A.VOYAGE = B.VOYAGE)
where b.depart = + comboBox1.Text + and b.weight = “zgxl” and(b.enddate between “2016-03-00” and “2016-04-00”) and(tallymen <> “” and tallymen is not null) and(res <> “1” and res <> “5”)
)a
group by 日期, 船公司, 英文船名, 中文船名, 航次, 进出口
order by 日期”;
SqlDataAdapter da = new SqlDataAdapter(strSQL, con); //创建DataAdapter数据适配器实例
DataSet ds = new DataSet();//创建DataSet实例
da.Fill(ds, “自定义虚拟表名”); //使用DataAdapter的Fill方法(填充),调用SELECT命令
dataGridView1.DataSource = ds.Tables[0].DefaultView;
string strSQL = @”Select ROW_NUMBER() OVER (ORDER BY 船公司 DESC) AS 序号,日期,船公司,英文船名,中文船名,航次,进出口,SUM(e20) e20, SUM(e40) e40, SUM(e45) e45, SUM(f20) f20, SUM(f40) f40, SUM(f45) f45,sum(teu) 合计teu
from
(
select CONVERT(VARCHAR, CAST(b.enddate AS DATE), 111) AS 日期, b.WEIGHT as 船公司, b.shipname as 英文船名, b.cshipname as 中文船名, b.voyage as 航次, b.ieflag as 进出口,
CASE WHEN(a.ewflag = “E” AND a.ssize = “20”)THEN 1 ELSE 0 END AS e20,
CASE WHEN(a.ewflag = “E” AND a.ssize = “40”)THEN 1 ELSE 0 END AS e40,
CASE WHEN(a.ewflag = “E” AND a.ssize = “45”)THEN 1 ELSE 0 END AS e45,
CASE WHEN(a.ewflag = “F” AND a.ssize = “20”)THEN 1 ELSE 0 END AS f20,
CASE WHEN(a.ewflag = “F” AND a.ssize = “40”)THEN 1 ELSE 0 END AS f40,
CASE WHEN(a.ewflag = “F” AND a.ssize = “45”)THEN 1 ELSE 0 END AS f45,
case a.ssize WHEN “45” THEN 2.25 WHEN “40” THEN 2 WHEN “20” THEN 1 ELSE 2.25 END AS teu
FROM container a
left join ships b ON(A.SHIPNAME = B.SHIPNAME AND A.VOYAGE = B.VOYAGE)
where b.depart = + comboBox1.Text + and b.weight = “zgxl” and(b.enddate between “2016-03-00” and “2016-04-00”) and(tallymen <> “” and tallymen is not null) and(res <> “1” and res <> “5”)
)a
group by 日期, 船公司, 英文船名, 中文船名, 航次, 进出口
order by 日期”;
SqlDataAdapter da = new SqlDataAdapter(strSQL, con); //创建DataAdapter数据适配器实例
DataSet ds = new DataSet();//创建DataSet实例
da.Fill(ds, “自定义虚拟表名”); //使用DataAdapter的Fill方法(填充),调用SELECT命令
dataGridView1.DataSource = ds.Tables[0].DefaultView;
解决方案
20
+1
应该是: string str=”select * from table where b.depart = ‘ “+ comboBox1.Text+ ” ’ and ……”
20
标点符号应该是英文的,不行,你断点一下,把生成的sql语句放到查询分析器上运行一下,看看哪里有问题,你在查询分析器上修改没问题了,再改代码