使用orderby子句时sql querry问题 [英] sql querry issue while using orderby clause
本文介绍了使用orderby子句时sql querry问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的querry。
I used below querry.
string s = ("Select * INTO [" + textbox1.text+ "NDtemp] FROM ( Select * from [" + textbox1.text+ "markets] order by 1) as NTemp");
sqlcommand cmd = new sqlcommand (s, con);
if (((cmd.ExecuteNonQuery()) < 0))
{
MessageBox.Show("Records are not copied to temp table.");
}
它给我的错误是:在视图,内联函数,派生表,子中,order by子句无效querries和常见的子查询表达式。
请帮助我,我使用访问数据库执行此代码但是在使用sql时它给了我错误是否有什么我需要更改。
it is giving me error that: Order by clause is invalid in views,inline functions,derived tables,sub querries and,common sub-querries expressions.
Please help me, I executed this code by using access database but while using sql it is giving me error is there anything I need to change.
推荐答案
根本不能在此查询中使用Order By子句。实际上,在表中存储数据时,数据库不关心记录排序。当您要以某种形式向用户呈现记录时,排序只是一个问题。
You cannot use an Order By clause in this query at all. Really, databases don't care about record ordering when storing data in the tables. Ordering is only a concern when you're going to present the records to users in some form.
您可以在sql中使用TOP 100 PERCENT。
You can use TOP 100 PERCENT in your sql.
string s = ("Select * INTO [" + textbox1.text+ "NDtemp] FROM ( Select TOP 100 PERCENT * from [" + textbox1.text+ "markets] order by 1) as NTemp");
sqlcommand cmd = new sqlcommand (s, con);
if (((cmd.ExecuteNonQuery()) < 0))
{
MessageBox.Show("Records are not copied to temp table.");
}
这就是你如何在子查询中使用order by。
That is how you can use order by in a subquery.
这篇关于使用orderby子句时sql querry问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文