选择查询多个值应该是什么? [英] What should be the select query for multiple values ?

查看:159
本文介绍了选择查询多个值应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用带有SQL Server 2005的ASP.NET设计一个Webpge
后端有带后续列的表格
用户名,名称,电话1,电话2,年龄和其他一些列用于存储用户的详细信息.

我想以这样的方式选择,以便我输入

文本框中使用逗号分隔多个用户名
在选择结果中,我得到了与该用户名关联的所有电话号码.

例如

用户名名称Phone1 Phone2
abc@yahoo.com Abhi 9334459287 9334459288
def@yahoo.com索尼9935199351
efg@yahoo.com托尼9835198351 9835198351


从tblregistration中选择Phone1,Phone2,其中usernames = abc @ yahoo.com,def @ yahoo.com,efg @ yahoo.com


结果,我喜欢所有电话号码
9334459287 9334459288
9935199351
9835198351 9835198351

请帮助我.

Hi,
I am designing a webpge using asp.net with sql server 2005
in back end there is table with followding columns
username,name,phone1,phone2,age and some others columns are there for storing user''s details.

I would like to select in such a way so that i enter

more than one user name seperated with commas in textbox
in selection result i get all the phone numbers associated with that usernames.

For example

Usernames Name Phone1 Phone2
abc@yahoo.com Abhi 9334459287 9334459288
def@yahoo.com Sony 9935199351
efg@yahoo.com Tony 9835198351 9835198351


Select Phone1,Phone2 from tblregistration where usernames=abc@yahoo.com,def@yahoo.com,efg@yahoo.com


In result i like all the phone numbers
9334459287 9334459288
9935199351
9835198351 9835198351

Please help me.

推荐答案

查看以下内容:
Check this out: Parameterized IN clauses with ADO.NET and LINQ[^]


构建带有多个用户名作为条件的sql语句.
例如,如果用户输入3个用户名
build sql statement with multiple usernames as where conditions.
for example if user input 3 usernames
select tp1, tp2 from table1 where username =@username1 or username =@username2 or username = @username3


设置参数值时,您可能需要拆分用户输入并获得每个用户名,如下所示:
字符串输入="abc @ yahoo.com,def @ yahoo.com,efg @ yahoo.com";
string []用户名= input.Split('','');


you may need to split user input and get each user name like below when you set parameter values
string input ="abc@yahoo.com,def@yahoo.com,efg@yahoo.com";
string[] usernames =input.Split('','');


这篇关于选择查询多个值应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆