Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过将字符串转换、装箱或拆分为整数,按查询对其进行SQL排序_C#_Sql_Tsql_Sql Server 2008 R2 - Fatal编程技术网

C# 通过将字符串转换、装箱或拆分为整数,按查询对其进行SQL排序

C# 通过将字符串转换、装箱或拆分为整数,按查询对其进行SQL排序,c#,sql,tsql,sql-server-2008-r2,C#,Sql,Tsql,Sql Server 2008 R2,我必须对ChildID列使用Order by query,但ChildID列数据类型是string。是否可以使用装箱、拆分函数或转换,我使用的是C#和sql server r2 2008 ChildID 19/2014-2015, 20/2014-2015, 02/2014-2015, 01/2014-2015, 使用这个作为您的ORDERBY子句,它应该可以帮助您开始。如果在斜杠后有除2014-2015之外的任何内容,我怀疑您需要修改它 ORDER BY SU

我必须对ChildID列使用Order by query,但ChildID列数据类型是string。是否可以使用装箱、拆分函数或转换,我使用的是C#和sql server r2 2008

ChildID
    19/2014-2015,
    20/2014-2015,
    02/2014-2015,
    01/2014-2015,

使用这个作为您的ORDERBY子句,它应该可以帮助您开始。如果在斜杠后有除2014-2015之外的任何内容,我怀疑您需要修改它

ORDER BY SUBSTRING(ChildID, 1, CHARINDEX('/', ChildID))

所需的排序顺序是什么?您需要澄清您希望将其转换为什么以及以什么顺序显示。如果要拆分它,可以使用
子字符串
。您的意思是转换斜杠前面的字符,还是通过删除非数字字符将整个内容转换为整数?是,我想按以下顺序显示01/2014-2015 02/2014-2015 19/2014-2015 20/2014-2015@shashisampige:哪个位决定顺序?是01、02、19、20吗?非常感谢,先生,它工作得很好