fsdfsewtf
2017-04-02 13:23
采纳率: 100%
浏览 996

新手求帮忙,请大神帮忙解释一下sql语句的问题

请大神帮忙看看,这几句SQL语句有什么语法问题!!!
string sql = "select EmployeeId,EmployeeName,Gender,Birthday,DepartmentName from Employees";
sql += "inner join EmployeeDepartment on Employees.DepartmentId=EmployeeDepartment.DepartmentId";
sql += "where Employees.DepartmentId="+departmentId;
执行后的语句是这样:图片说明

where那好像没有隔开,求大神教具体应该怎么改

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • zhangyuanyincsdn 2017-04-02 14:19
    已采纳

    语法上没有问题,看输出语句后,检查下关键词间的空格吧

    已采纳该答案
    打赏 评论
  • 罗正波 2017-04-02 13:32

    把拼接好的sql语句打印看一下,我怀疑是inner 和where的空格问题

    打赏 评论
  • 秦大圣 2017-04-02 13:36

    两个字符串连接了,但是中间没有空格呀Employeesinner这样肯定设别不错来,不要这样写,容易错

    打赏 评论
  • AQ_xiaobin 2017-04-02 13:50

    string sql = "select EmployeeId,EmployeeName,Gender,Birthday,DepartmentName from Employees";
    sql += "inner join EmployeeDepartment on Employees.DepartmentId=EmployeeDepartment.DepartmentId";
    sql += "where Employees.DepartmentId="+departmentId;

    string sql复用了吧?
    string sql = "select EmployeeId,EmployeeName,Gender,Birthday,DepartmentName from Employees"

    • "inner join EmployeeDepartment on Employees.DepartmentId=EmployeeDepartment.DepartmentId"+ "where Employees.DepartmentId="+departmentId; 不知道对不对?
    打赏 评论
  • 一直很疑惑 2017-04-02 14:11

    执行完后的sql语句是这样的:
    select EmployeeId,EmployeeName,Gender,Birthday,DepartmentName from Employeesinner join EmployeeDepartment on Employees.DepartmentId=EmployeeDepartment.DepartmentIdwhere Employees.DepartmentId=1
    问题在拼接的地方没有空格隔开.

    打赏 评论
  • lhetiger 2017-04-03 17:19

    StringBuilder sql = new StringBuilder(" select EmployeeId,EmployeeName,Gender,Birthday,DepartmentName from Employees inner join EmployeeDepartment on Employees.DepartmentId=EmployeeDepartment.DepartmentId");
    sql.Append(string.Format(" where Employees.DepartmentId ={0}", departmentId));
    ExcuteSql(sql.toString());

    打赏 评论

相关推荐 更多相似问题