如何编写除一列以外的选择查询 [英] how to write select query except one column

查看:89
本文介绍了如何编写除一列以外的选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有20列作为日期,col1,col2 .... col19。

i想要显示除日期列之外的所有列。

如何写查询。

i have 20 columns as date,col1,col2....col19.
i want to display all columns except date column.
how to write query for that.

推荐答案

从select语句中删除该列并放入所有其他列名。

或者您可以绑定所有列并隐藏特定的代码中的列。例如,如果将数据绑定到GridView,则添加RowDataBound事件并将第一列隐藏为;



remove that column from your select statement and put all other column names.
Or you can bind all the columns and hide specific column from code. for example if you bind data to GridView then add RowDataBound event and hide the first column as;

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Cells[0].Visible = false;
}






参考:是否可以编写选择*除了表中的(column1,column2,..)


如果您要经常使用此查询,则以前解决方案的另一种替代方法是创建查看 [ ^ ]数据。



同样的限制适用(即你可以不要说除了这些列,但查询只会在SSMS中编写或构建一次。在更高版本的sql中,您可以为视图索引性能。



如果表中有60列,那么您可能想重新考虑表模式并使用一些规范化技术 [ ^ ]
Another alternative to the previous solutions, if you are going to use this query frequently, is to create a View[^] of the data.

The same restrictions apply (i.e. you can't say "except these columns") but the query will only be written, or built in SSMS, once. In later versions of sql you can index views for performance.

If you have 60 columns in your table then you might like to re-consider your table schema and employ some normalization techniques[^]


这篇关于如何编写除一列以外的选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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