日期:2014-05-18 浏览次数:20729 次
---------------------------- -- Author :fredrickhu(小F,向高手学习) -- Date :2011-12-17 15:42:33 -- Version: -- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) -- Apr 22 2011 11:57:00 -- Copyright (c) Microsoft Corporation -- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64) -- ---------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([mc] varchar(49)) insert [tb] select 'QQ卡|神州行充值卡|20QB|网易一卡通|骏网一卡通|玩偶' --------------开始查询-------------------------- Select 顺序编号=ROW_NUMBER()over(order by getdate()), mc=substring(a.mc,b.number,charindex('|',a.mc+'|',b.number)-b.number) from Tb a join master..spt_values b ON B.type='p' AND B.number BETWEEN 1 AND LEN(A.mc) where substring('|'+a.mc,b.number,1)='|' ----------------结果---------------------------- /* 顺序编号 mc -------------------- ------------------------------------------------- 1 QQ卡 2 神州行充值卡 3 20QB 4 网易一卡通 5 骏网一卡通 6 玩偶 (6 行受影响) */