以格式提取数据的问题 [英] problem with fetching data in format

查看:53
本文介绍了以格式提取数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我写了一个查询:从员工中选择员工,其中employeeid在(2,3,5,1)

然后我想根据2,3获取数据,5,1订单。但它显示1,2,3,5明智请帮帮我?

选择m.MachineID,求职码,故障,运行,FaultLimitExceed,ProdCount来自机器管理员m内部加入machinestatuspara s+on m .machineid = s.machineid其中m.machineid不为null且m.machineid为(2,1);



ans:

'1','1','0','0','0','2377','00:57:42','31 -10-2014'

'2 ','3','0','0','0','1492','00:57:35','31 -10-2014'

但我想要





'2','3','0','0','0','1492','00:57 :35','31 -10-2014'

'1','1','0','0','0','2377','00:57:42' ,'31 -10-2014'

suppose i wrote query :select employees from employee where employeeid in(2,3,5,1)
then i want to fetch data according to 2,3,5,1 order. but it display 1 ,2,3,5 wise please help me?
"select m.MachineID,jobcode,Fault,Running,FaultLimitExceed,ProdCount from machinemaster m inner join machinestatuspara s " +" on m.machineid=s.machineid where m.machineid is not null and m.machineid in(2,1)";

ans:
'1', '1', '0', '0', '0', '2377', '00:57:42', '31-10-2014'
'2', '3', '0', '0', '0', '1492', '00:57:35', '31-10-2014'
but i want


'2', '3', '0', '0', '0', '1492', '00:57:35', '31-10-2014'
'1', '1', '0', '0', '0', '2377', '00:57:42', '31-10-2014'

推荐答案

Please use below example, it's helpful for you.
<pre lang="sql">create table #temp
(
empid int
)

insert into #temp(empid) values(1)
insert into #temp(empid) values(2)
insert into #temp(empid) values(3)
insert into #temp(empid) values(5)


select * from #temp order by empid%2</pre>


您好,

因为有主键在桌子上。因此,您将始终通过Ascending子句获取订单。由于聚簇索引。请参阅链接更多说明:代码项目:索引

MSDN



有一种可能的解决方案。你需要为它创建一个存储过程。我首先在临时表中插入一个记录。在那个临时表上修改一个PRimary Key。然后按顺序插入你想要的记录。



希望它可以帮助你。
Hello ,
As there is a primary Key on the table. so,you will always get the order by Ascending clause.Because of clustered Indexes.Refer the link For More Explanation:Code Project:Indexes
MSDN

There is one possible solution. you need to make a stored procedure for this.In which First Insert a Record in the temp table.Created a PRimary Key on that temp table.Then Insert the record in sequence in which you want one by one.

Hope It Might Helps You.


这篇关于以格式提取数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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