Visual c#中的SQL SELECT和多个AND查询语句

时间:2022-01-12 23:01:10

In this query statement i want sum of the number of days in the 'datetime' column where emp_ID equals to selected emp_ID in the textBox2 'and' leavetype = Fullday 'and' status = approved. this is my code

在此查询语句中,我想要'datetime'列中天数的总和,其中emp_ID等于textBox2'和'leavetype = Fullday'和'status = approved中选定的emp_ID。这是我的代码

string selectSql = 
"Select sum(datetime) 
 From Lea_information 
 Where emp_ID= ('" + textBox2.Text + "') 
 and (leave_type,status) = values (Fullday,Approved)";

2 个解决方案

#1


0  

Try like this

试试这样吧

string selectSql = 
"Select sum(datetime) 
 From Lea_information 
 Where emp_ID= '" + textBox2.Text + "'
 AND leave_type ='Fullday' 
 AND status = 'Approved'";

#2


0  

Use

ing selectSql = "Select sum(datetime) from Lea_information where emp_ID= ('" + textBox2.Text + "') and leave_type = FullDay and status = Approved)";

Not sure which database you are using, but I've never seen statements like you have written there before.

不确定您使用的是哪个数据库,但我从未见过您之前写过的语句。

#1


0  

Try like this

试试这样吧

string selectSql = 
"Select sum(datetime) 
 From Lea_information 
 Where emp_ID= '" + textBox2.Text + "'
 AND leave_type ='Fullday' 
 AND status = 'Approved'";

#2


0  

Use

ing selectSql = "Select sum(datetime) from Lea_information where emp_ID= ('" + textBox2.Text + "') and leave_type = FullDay and status = Approved)";

Not sure which database you are using, but I've never seen statements like you have written there before.

不确定您使用的是哪个数据库,但我从未见过您之前写过的语句。