在asp.net中选择with和condition [英] select with and condition in asp.net
本文介绍了在asp.net中选择with和condition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数据库,如
i have database like
id=1111 and fighi="1AoHere"
id=3333 and fighi="3AoHere"
id=1111 and fighi="12AoHere"
idl=3333 and fighi="32AoHere"
id=1111 and fighi="11AoHere"
id=3333 and fighi="31AoHere"
id=11121 and fighi="12AoHere"
idl=33332 and fighi="32AoHere"
i想要使用数据表的选择查询来获取查询的下方(选择id = '1111'和id ='2222')
in datatable
i want to use select query for datatable to get below for query (select id='1111' and id='2222')
1AoHere,12AoHere,11AoHere all these for id=1111
3AoHere,32AoHere,31AoHere all these for id =3333
推荐答案
试试这个:
Try this:
SELECT Id, fighi=
STUFF((SELECT ',' + CONVERT(VarChar(10), fighi)
FROM MyTable b
WHERE b.Id = a.lId
FOR XML PATH('')), 1, 1, '')
FROM MyTable a
WHERE Id IN (1111, 3333)
GROUP BY Id
< br>
使用 Datatable.Select [ ^ ]或 Dataview.RowFilter [ ^ ]
使用此:
Use thise:
SELECT ID, FIGHI
FROM TableName
WHERE ID IN (111, 333)
或
or
SELECT ID, FIGHI
FROM TableName
WHERE (ID =111) OR (ID =333)
您不能将 AND
运算符与 WHERE
语句一起使用,因为 ID
同时不能等于 111
和 333
。它可以等于 111
或 333
。
You can't use AND
operator with WHERE
statement, because ID
can't be equal to 111
and 333
at the same time. It can be equal 111
or 333
.
这篇关于在asp.net中选择with和condition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文