sql server 中关于字符串的截取
[ 2005-11-13 23:10:39 | 作者: admin ]
[test]表的按varchar类型字段demo排序的实现
demo字段
---------------
1LP1
1LP2
2LP1
3LP3
19LP23
23LP1
首先显示测试
---------------------------------
SELECT CAST(LEFT(demo, CHARINDEX('LP', demo) - 1) AS int) AS Expr1,
CAST(RIGHT(demo, LEN(demo) - CHARINDEX('LP', demo) - 1) AS int) AS Expr2
FROM test
结论
-----------------------------------
SELECT *
FROM test
ORDER BY
CAST(LEFT(demo, CHARINDEX('LP', demo) - 1) AS int),
CAST(RIGHT(demo, LEN(demo) - CHARINDEX('LP', demo) - 1) AS int)
demo字段
---------------
1LP1
1LP2
2LP1
3LP3
19LP23
23LP1
首先显示测试
---------------------------------
SELECT CAST(LEFT(demo, CHARINDEX('LP', demo) - 1) AS int) AS Expr1,
CAST(RIGHT(demo, LEN(demo) - CHARINDEX('LP', demo) - 1) AS int) AS Expr2
FROM test
结论
-----------------------------------
SELECT *
FROM test
ORDER BY
CAST(LEFT(demo, CHARINDEX('LP', demo) - 1) AS int),
CAST(RIGHT(demo, LEN(demo) - CHARINDEX('LP', demo) - 1) AS int)
[最后修改由 admin, 于 2006-05-16 12:41:00]
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=196
这篇日志没有评论。
此日志不可发表评论。