在sql server-2005中对varchar字段进行排序 [英] sort varchar field in sql server-2005

查看:98
本文介绍了在sql server-2005中对varchar字段进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生,

我在一个实时项目中工作.我想要对代码(URC CODE)进行排序.
代码没有任何特定的模式,这意味着我们可以为此代码输入任何内容,例如数字,字符串,字母数字字符.

我已将此urccode作为字段以varchar形式存储在数据库中.
并在我的Crystal Reports中使用此字段.我必须在我的crytsal报告中按升序显示urc代码.
例如.



1
2
3
1.2.3
2.1.2
2.1A.2
2.1.1A.3
A1.01
A1.2
A2.1A
A1.2A.2.3

排序顺序为:
1
1.2.3

2
2.1.2
2.1A.2
2.1.1A.3

3
A1.1
A1.2
A1.2A.2.3
A2.1A
.
.
.
等等

所以任何人都可以在sql server-20005中告诉我有关此代码的信息
或任何博客,因为我搜索了许多博客,但没有找到任何解决方案.

谢谢

hello sir,

I m working in a real time project. I want a sorting on a code(URC CODE).
Code doesnt have any particular pattern means we can enter anything for this code like numbers,Strings,alphanumeric characters.

I have stored this urccode as a field in database in varchar form.
and using this field in my crystal reports.i have to show urc code in ascending order in my crytsal reports
for ex.



1
2
3
1.2.3
2.1.2
2.1A.2
2.1.1A.3
A1.01
A1.2
A2.1A
A1.2A.2.3

sorted order is:
1
1.2.3

2
2.1.2
2.1A.2
2.1.1A.3

3
A1.1
A1.2
A1.2A.2.3
A2.1A
.
.
.
so on

so can anyone please tell me code for this in sql server-20005
or any blog as i searched many blogs but didnt find any solution for this.

Thanks

推荐答案

代码没有任何特定的模式,这意味着我们可以为该代码输入任何内容,例如数字,字符串,字母数字字符...

看起来像是对我排序的字典.如果是这样,那是什么问题?继续并使用SORT方法.

没有*代码*.您可以在获取数据时在数据库中或在业务层中对数据进行排序,然后再将数据传递给报表.

实际上,我认为即使对Report中的此列进行排序也应为您服务!只需按报告中的此列对数据进行排序即可.
Code doesnt have any particular pattern means we can enter anything for this code like numbers,Strings,alphanumeric characters...

Looks like a Dictionary sorting to me. If so, what is the problem? Go ahead and use the SORT method.

There is no *code* for it. You can either sort it in Database while fetching or in your Business Layer before passing the data to Report.

In fact, I think even Sorting of this column in Report should also do for you! Just sort the data by this column in your report.


示例:

按列名从表名中选择[column_name] asc


以上是简单的查询.
如果需要,可以在存储过程中实施排序依据",以便在Crystal报表中获取所需的输出.
Example:

SELECT [column_name] FROM table_name order by column_name asc


Above is simple query.
If you want you can implement sort by in your stored procedure to get the required output in your crystal report.


这篇关于在sql server-2005中对varchar字段进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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