用于检索数据的SQL查询 [英] sql query for retrieving data
本文介绍了用于检索数据的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的表
This is my table
Account_id Cost_Accid
100 60
200 40
500 60
100 30
在我的表单中有2个文本框。一个用于帐户ID,另一个用于帐户ID现在我想要检索数据如下..
它应该显示
当acc_id = 100时,所有字段都是100,
当cost_accid = 60时所有字段为60,
当acc_id = 100且cost_accid = 60时所有字段...
单个sql查询是什么?
In my form there is 2 text boxes.one for account id and another for cost accid.
now i want to retrieve data as follows..
it should display
all fields of 100 when acc_id=100,
all fields of 60 when cost_accid=60,
all fields when acc_id=100 and cost_accid=60...
What is the single sql query for this?
推荐答案
SELECT * FROM MyTable
WHERE acc_id=100 OR cost_accid=60 OR (acc_id=100 and cost_accid=60)
请检查一下...
Hi,
Kindly check this...
--@txt_accId & @txt_cost_accId are variables of 2 text boxes respectively.
SELECT * FROM MyTable
Where acc_id= CASE WHEN @txt_accId='' THEN acc_id ELSE @txt_accId END
AND cost_accid= CASE WHEN @txt_cost_accId='' THEN cost_accid ELSE @txt_cost_accId END
< br $> b $ b
希望这会h elp you。
干杯
Hope this will help you.
Cheers
这篇关于用于检索数据的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文