select * from tbxx order by have_son desc,level asc
--你的排序无规律吧?
--你的排序无规律吧?
解决方案 »
- 动态语句中如何使用/
- 求解如何查询日期段内,按周统计天数,不涉及用户表
- mysql 数据备份
- 大侠们,这个查询怎样写??
- 两个数据库程序如何保存一定顺序访问数据库?
- ■■■■■■■■■ACCESS数据库,怎么导出表结构啊。■■■■■■■■■up有分
- SQLServer2005 安装问题
- 想学习C#,没有编程的基础,如果入门可以学好呢?有什么书或教程介绍下呢?
- 我想建一个,每天全国各个城市的某种产品价格行情表,请大伙帮忙设计一下?
- *******为什么文件被打开而不是提示下载?????*******
- 这样的数据库结构该如何设计(在线等)
- 各位大哥帮帮忙给想想办法,关于SQLServer2000数据库数据量的传输和服务器硬件性能的监测报告
returns varchar(8000)
as
begin
declare @ret varchar(8000)
select
@ret = right('0000'+module_id,4),
@module_id = parent_id
from
表
where
module_id = @module_id
while(@@rowcount<>0)
select
@ret = right('0000'+module_id,4)+@ret,
@module_id = parent_id
from
表
where
module_id = @module_id and @module_id != 0
return @ret
end
--调用函数
select * from 表 order by dbo.f_getorder(module_id)
http://blog.csdn.net/xluzhong/articles/340928.aspx
create function list(@in int)
returns @out int
as
begin
set @out=@in
return @out
end
create function list(@in int)
returns Int
as
begin
Declare @out Int
set @out=@in
return @out
end
你的好象有些问题select dbo.f_getorder(module_id) from tb
1
12
13
124
125
1246
但是id好超过10好像就不行了
如果我要返回2个Int,应该怎样写
insert 表 select 1 , 0 , 1 , '总公司' , 1
insert 表 select 2 , 1 , 2 , '分公司1' , 1
insert 表 select 3 , 1 , 2 , '分公司2' , 0
insert 表 select 4 , 2 , 3 , '开发部' , 1
insert 表 select 5 , 2 , 3 , '销售部' , 0
insert 表 select 6 , 4 , 4 , '办公室' , 0
insert 表 select 10 , 1 , 4 , '分公司3' , 0
就不对了
-----------------------------------------------------------
alter function f_getorder(@module_id int)
returns varchar(8000)
as
begin
declare @ret varchar(8000)
select
@ret = right('0000'+rtrim(module_id),4),
@module_id = parent_id
from
表
where
module_id = @module_id
while(@@rowcount<>0)
select
@ret = right('0000'+rtrim(module_id),4)+@ret,
@module_id = parent_id
from
表
where
module_id = @module_id and @module_id != 0
return @ret
end
to paoluo(一天到晚游泳的鱼):
如果我要返回2个Int,应该怎样写
-------------------------------------------函数不能返回两个Int,不过你可以返回一个表变量,你在表变量中给两个Int字段。
create function list(@in int)
returns @Tesult Table(Out1 Int,Out2 Int)
as
begin
Insert @Tesult Values(@in,@in)
return
end
GO
Select * from dbo.list(1)