如作甚下面给出的查询编写等效的SQL case语句?
发布时间:2021-01-19 22:22:58 所属栏目:编程 来源:网络整理
导读:这是我的事变查询: Query = "select Cust_Id,Card_Number,Clients_Title,Address_Current,Phone_Number,Mobile_Number from Customer_New Where 1=1";try{ if (txt_title.Text != "") Query += " and Clients_Title Like '%" + txt_title.Text + "%'"; if (t
|
这是我的事变查询: Query = "select Cust_Id,Card_Number,Clients_Title,Address_Current,Phone_Number,Mobile_Number from Customer_New Where 1=1";
try
{
if (txt_title.Text != "")
Query += " and Clients_Title Like '%" + txt_title.Text + "%'";
if (txt_address.Text != "")
Query += " and Address_Current Like '%" + txt_address.Text + "%'";
if (txt_phone.Text != "")
Query += " and Phone_Number Like '%" + txt_phone.Text + "%'";
if (txt_mobile.Text != "")
Query += " and Mobile_Number Like '%" + txt_mobile.Text + "%'";
if (cbo_location.Text != "")
Query += " and AreaLocation Like '%" + cbo_location.Text + "%'";
}
catch { }
在这里,我试图编写其等效的SQL case语句. SELECT Cust_Id,Key_Person,Mobile_Number,AreaLocation
FROM Customer_New
WHERE 1 = CASE WHEN @Clients_Title != " " THEN Clients_Title AND
WHEN @Address_Current != " " THEN Address_Current AND
WHEN @Phone_Number != " " THEN Phone_Number AND
WHEN @Mobile_Number != " " THEN Mobile_Number AND
WHEN @AreaLocation != " " THEN AreaLocation
END
任何人都能更正我的案件告诉吗? 办理要领我想你只想要这个 – 不必要CASE:SELECT Cust_Id,AreaLocation
FROM Customer_New
WHERE
(@Clients_Title = '' OR Clients_Title LIKE '%'+@Clients_Title+'%') AND
(@Address_Current = '' OR Address_Current LIKE '%'+@Address_Current+'%') AND
(@Phone_Number = '' OR Phone_Number LIKE '%'+@Phone_Number+'%') AND
(@Mobile_Number = '' OR Mobile_Number LIKE '%'+@Mobile_Number+'%') AND
(@AreaLocation = '' OR AreaLocation LIKE '%'+@AreaLocation+'%')
由于这至少很是相同于非SQL代码. (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


