Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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
Sorting SQL CE(精简版)3.5版中的字母数字字段排序_Sorting_Sql Order By_Sql Server Ce_Alphanumeric - Fatal编程技术网

Sorting SQL CE(精简版)3.5版中的字母数字字段排序

Sorting SQL CE(精简版)3.5版中的字母数字字段排序,sorting,sql-order-by,sql-server-ce,alphanumeric,Sorting,Sql Order By,Sql Server Ce,Alphanumeric,SQL CE Compact Edition 3.5版中的字母数字字段排序 TreeNumber是一个nvarchar字段,其值混合了数字和字符串。我想对这些记录进行排序,使包含字母字符的记录位于顶部,其余的按数字顺序排序 我需要类似于以下在SQL Server中工作的查询: SELECT * FROM Tree ORDER BY (CASE WHEN TreeNumber LIKE '%[a-z]%' THEN 0 ELSE TreeNumber END), TreeNumber

SQL CE Compact Edition 3.5版中的字母数字字段排序

TreeNumber是一个nvarchar字段,其值混合了数字和字符串。我想对这些记录进行排序,使包含字母字符的记录位于顶部,其余的按数字顺序排序

我需要类似于以下在SQL Server中工作的查询:

SELECT * FROM Tree
ORDER BY 
    (CASE WHEN TreeNumber LIKE '%[a-z]%' THEN 0 ELSE TreeNumber END), TreeNumber
上面的查询似乎不起作用,因为CE不支持[]范围。另一个与SQL Server配合使用但因不支持IsNumber而无法在CE中工作的解决方案如下:

SELECT * FROM Tree 
ORDER BY 
    (CASE IsNumeric(TreeNumber) WHEN 0 THEN 0 ELSE TreeNumber END), TreeNumber

CE是否支持功能?例如,您可以将自己的IsNuemric函数设置为一个简单的逐字符解析器,稍后在查询中调用它

好的,这个解决方案很难看,而且不适合胆小的人。我没有在SQLCE上进行测试,但它只使用基本的t-SQL,所以应该可以。如果你不想读的话,你必须创建一个只需运行他的第一段代码。它使用tempdb,因此您需要对其进行更改,并且由于缺少模式匹配函数,它还提供了一个表来保存字母表中的每个字母。创建理货表后,您不必像示例所示一直到11000,运行这些,您将看到所需的排序行为

为演示目的创建字母表temp:

select *
into #alphatable
from
(

select 'A' as alpha union all
select 'B' union all
select 'C' union all
select 'D'
--etc. etc.
) x
select *
into #tree
from
(

select 'aagew' as TreeNumber union all
select '3' union all
select 'bsfreww' union all
select '1' union all
select 'xcaswf' 
) x
为演示目的创建树表temp:

select *
into #alphatable
from
(

select 'A' as alpha union all
select 'B' union all
select 'C' union all
select 'D'
--etc. etc.
) x
select *
into #tree
from
(

select 'aagew' as TreeNumber union all
select '3' union all
select 'bsfreww' union all
select '1' union all
select 'xcaswf' 
) x
解决方案:

select TreeNumber
from
(
select t.*, tr.*, substring(TreeNumber, case when N >  len(TreeNumber) then len(TreeNumber) else N end, 1) as singleChar
from tally t
cross join #tree tr
where t.N < (select max(len(TreeNumber)) from #tree)

) z
left join
#alphatable a
on z.singlechar = a.alpha
group by TreeNumber

order by case when max(alpha) is not null then 0 else TreeNumber end 
这基本上是Moden描述的一种技术,即通过字符进行单步扫描,然后将每个字符连接到alpha表中。字母表中没有行的行是数字