日期:2014-05-17 浏览次数:20753 次
Declare @class varchar(50),@point varchar(80) set @class = ?;set @know_point = ? SELECT u1.[user_id],u1.[user_name], [test_result] = (CASE WHEN [test_result] IS NULL THEN -1 ELSE [test_result] END) FROM (SELECT u2.[user_id],u2.[user_name] FROM users AS u2 WHERE (u2.class = @class) AS u1 LEFT JOIN (SELECT * FROM [prep_result] AS sr2 WHERE sr2.[know_point]= @know_point) AS sr1 ON u1.[user_id] = sr1.[user_id]
p.setString(1,"1班");//设置第一个参数(@class) p.setString(2, "A");//设置第二个参数(@point) rs = p.executeQuery();//执行查找的sql语句 while(rs.next()){ String userId = rs.getString("user_id");//经调试数据正常 String userName = rs.getString("user_name");//经调试数据正常 int result = rs.getInt("test_result");//这里!result的值全为-1,但在查询分析器那是有成绩的,表中也有成绩的! }