我没有得到asc命令(我想要val_name asc命令,但是我得到了dis) [英] i am not getting asc order(i want val_name asc order but i am getting like dis)

查看:121
本文介绍了我没有得到asc命令(我想要val_name asc命令,但是我得到了dis)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public DataSet GetContractTerm(string prodKey, int propLinkID, OleDbConnection conn)
        {
            string sQuery;
            string Prod_Friendly_Name = string.Empty;
   sQuery = "select distinct VAL_ID, VAL_NAME from PPSR_OWNER.ppsr_q2o_att_data_v  where attribute_name = 'CONTRACT TERM'   ORDER BY VAL_NAME ASC";           
 DataSet dsContractTerm = new DataSet();

            try
            {
                dsContractTerm = CCBusiness.Utility.OracleHelperUtility.ExecuteDataset(conn, sQuery);
            }
            catch (Exception e)
            {
                CCBusiness.Utility.OracleHelperUtility.LogPPSRError(System.Web.HttpContext.Current, e);
                throw e;
            }
            return dsContractTerm;

}

private string GetContractName(DataSet ds, string contractID)
        {
            string contractname = string.Empty;

            for (int contract = 0; contract < ds.Tables[0].Rows.Count; contract++)
            {
                if (contractID == ds.Tables[0].Rows[contract]["VAL_ID"].ToString())
                {
                    contractname = ds.Tables[0].Rows[contract]["VAL_NAME"].ToString();
                    break;
                }

            }
            return contractname;
        }


获得结果
1
10
11
12
13
14
15
16
17
18
19
2
20
21
22
23
3
30
31
预期结果
1
2
3
4
5
6
7
8
9
10
11


Gettingresult
1
10
11
12
13
14
15
16
17
18
19
2
20
21
22
23
3
30
31
Expected result
1
2
3
4
5
6
7
8
9
10
11

推荐答案

我认为您需要将VAL_NAME转换为Number.

例如.
I think you need to convert VAL_NAME to Number.

eg.
ORDER BY CAST(VAL_NAME AS NUMBER)



谢谢,
Imdadhusen



Thanks,
Imdadhusen


如果您声明为输出的确实来自VAL_NAME列,并且VAL_NAME列的类型为字符类型(例如varchar等),则不要感到惊讶,因为排序字符串与对整数排序无关.

如果您的输出显示的是VAR_ID列,那么您也不应该感到惊讶,因为您不是按VAL_ID而是按VAR_NAME进行排序.

首先,把这两个陈述都包括在内,我可以告诉你:不要惊讶.
要进行更详细的分析,我们需要您提供更多信息.特别是您发布的代码不会向我们显示正在输出哪些字段,因此根本没有帮助.

最好的问候,

-MRB
If what you declared as your output is indeed from column VAL_NAME and the type of column VAL_NAME is of a character type (e.g. varchar etc.) then you should not be surprised, since sorting strings has nothing to do with sorting integers.

If what your output shows is column VAR_ID then you should also not be surprised since you aren''t ordering by VAL_ID, but rather by VAR_NAME.

Subsummizing the two statements above all I CAN tell you this: Do not be surprised.

For a more detailed analysis we need more information from your side. Especially the code which you posted doesn''t show us what fields are being output and is thus not helpful at all.

Best Regards,

-MRB


尝试此查询

try this query

select distinct VAL_ID, VAL_NAME from PPSR_OWNER.ppsr_q2o_att_data_v  where attribute_name = ''CONTRACT TERM''  ORDER BY Convert(Decimal,VAL_NAME) ASC


这篇关于我没有得到asc命令(我想要val_name asc命令,但是我得到了dis)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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