数据库语句的问题 如果一个数据表中有两个子段都记录时间,为a,b.要求:写一个select句子,如果a不为空的时候,按照a的降序排列,如果a为空(NULL),则按b的降序排列, select * from [表名] order by 后面应该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写存储过程伪代码Declare aa变量,bb变量select count(a) into aa from tableif aa>0 thenselect * from table order by aelseselect * from table order by bend if 还有一种方法就是,把你的SQL语句分开写,也就是将楼上所说的存储过程中的语句分开成三步来写,即先进行判断 if exsits(select a from table) GO select * from table order by a desc select * from table order by b desc 问题补充:我是在c#后台代码中(做的是asp.net项目)写这段程序的,有没有好一点的解决方法?谢谢各位大虾 string OrderbyWhere=(a==""||a==null)?"order by b":"order by a";string strsql="select * from table "+OrderbyWhere; select count(a) into aa from table where a is not nullorder by a/b desc 如果将字符串保存为一个xml? 新手求解asp.net即时获取文本框中的值... 关于DATAGIRD 数据绑定的问题 数据库中存有图片地址路径和文字,如何只读出图片的路径? 请教如何在一个进程内调用同一ActiveX控件的多个副本? DataGrid中DataKeyField指定两个列,后台如何使用,谢谢! 打开和创建web应用程序时遇到的速度问题 关于datagrid模板列中填加控件的疑问(非常简单) 数据绑定的时候出问题了 ASP.NET中如何在WEB页面上自由拖动图片? gridview怎样合并表头,并固定之,十万火急!!!!!!!!!!! .net网站发布后的问题
伪代码
Declare aa变量,bb变量
select count(a) into aa from table
if aa>0 then
select * from table order by a
else
select * from table order by b
end if
GO
select * from table order by a desc
select * from table order by b desc
string OrderbyWhere=(a==""||a==null)?"order by b":"order by a";
string strsql="select * from table "+OrderbyWhere;