从字符串中获取中间值

时间:2015-06-11 14:15:55

标签: sql sql-server pattern-matching

让我说我有一个值列表,格式如下:

  

BookIndex - 重视我需要的东西 - 随机的东西

BookIndex - B 12x - AXD39
BookIndex - A 99a - PZT00

...

问题:如何以尽可能少的功能获得我需要的价值?

输出

B 12x
A 99a

2 个答案:

答案 0 :(得分:0)

基于您的问题主题回答:SUBSTRING(FieldName,StartIndex,Length)

  

任何一般性答案?因为我没有静态的价值长度。

查找StartIndex和End索引。在您的样本中,您需要在char' - '

之间添加文本
select SUBSTRING(TextData, CHARINDEX('-', TextData), CHARINDEX('-', TextData, CHARINDEX('-', TextData) + 1)) as E1 from [Untitled - 1] 

答案 1 :(得分:0)

x = np.arange(10, 30); y= np.arange(10, 30)
X, Y = np.meshgrid(x, y, indexing='ij')

Z
array([[-1.23899351, -1.23326499, -1.22561211, -1.22222831, -1.21818137,
        -1.2129878 , -1.20895897, -1.2054236 , -1.20192976, -1.19604206,
        -1.19193082, -1.18911284, -1.18359125, -1.18080106, -1.17528045,
        -1.17045489, -1.16615841, -1.1607841 , -1.15581394, -1.14977876],
       [-1.23108045, -1.22469352, -1.21624837, -1.21262379, -1.20839915,
        -1.20305528, -1.19915268, -1.19594966, -1.19294162, -1.18742779,
        -1.18400632, -1.18213109, -1.17737072, -1.17572093, -1.17113012,
        -1.167374  , -1.16425803, -1.15999452, -1.15621331, -1.1512805 ],
       [-1.22442436, -1.21734909, -1.20802694, -1.20402883, -1.19944585,
        -1.19372874, -1.18969655, -1.1865441 , -1.18372095, -1.17826507,
        -1.17521266, -1.17395937, -1.16963921, -1.16881801, -1.16485107,
        -1.16187026, -1.15965389, -1.15623271, -1.15338689, -1.14931636],
       [-1.21888629, -1.21113743, -1.20091498, -1.19648643, -1.19145116,
        -1.18523176, -1.18091181, -1.17762645, -1.17478368, -1.16916239,
        -1.16624565, -1.16537453, -1.16124778, -1.16101046, -1.15742132,
        -1.15497453, -1.1534229 , -1.15061511, -1.14848457, -1.14506403],
       [-1.21433065, -1.20594351, -1.19482955, -1.18995671, -1.18442771,
        -1.17763699, -1.17293649, -1.16940333, -1.16640636, -1.16046578,
        -1.15751912, -1.15685549, -1.15273681, -1.15289614, -1.14949172,
        -1.14738603, -1.14630804, -1.14392384, -1.14232316, -1.1393707 ],
       [-1.21063639, -1.20165455, -1.1896737 , -1.18436635, -1.17833317,
        -1.17093953, -1.16580839, -1.16195926, -1.15872283, -1.15235981,
        -1.14926871, -1.14868834, -1.14444143, -1.14485723, -1.14148903,
        -1.13957342, -1.13881686, -1.13670227, -1.13547876, -1.13284207],
       [-1.20769912, -1.19816836, -1.18535223, -1.17963251, -1.17310242,
        -1.16509703, -1.15951253, -1.1553104 , -1.15178339, -1.14493098,
        -1.14161846, -1.14103529, -1.13656184, -1.1371314 , -1.13368724,
        -1.13184552, -1.13129138, -1.12932369, -1.12835387, -1.12590774],
       [-1.20542994, -1.19539531, -1.18177786, -1.17567387, -1.16866384,
        -1.16005137, -1.15400789, -1.14943614, -1.14559063, -1.13820727,
        -1.13462349, -1.13397974, -1.12921035, -1.12986007, -1.1262566 ,
        -1.12440093, -1.12395768, -1.12204056, -1.12122615, -1.1188692 ],
       [-1.20375343, -1.1932579 , -1.17887305, -1.17241522, -1.16494718,
        -1.15573999, -1.1492424 , -1.1442975 , -1.14012105, -1.13218275,
        -1.12829715, -1.12755571, -1.12244257, -1.12312109, -1.1192975 ,
        -1.11736254, -1.11696094, -1.11501988, -1.11428378, -1.11193497],
       [-1.20260543, -1.19168943, -1.17656983, -1.16978901, -1.16188707,
        -1.15210164, -1.14516099, -1.13984764, -1.13533801, -1.12683267,
        -1.12262823, -1.12176688, -1.11627809, -1.11695088, -1.11286363,
        -1.1108017 , -1.11039027, -1.10836845, -1.10765101, -1.10524638],
       [-1.20193121, -1.19063246, -1.17480899, -1.16773538, -1.15942425,
        -1.14907902, -1.14170982, -1.13603774, -1.13119921, -1.12212272,
        -1.11759178, -1.1165989 , -1.11071417, -1.11135918, -1.10697789,
        -1.10475496, -1.10429624, -1.10215097, -1.10140672, -1.09889635],
       [-1.20168386, -1.19003744, -1.17353898, -1.16620161, -1.1575057 ,
        -1.14661978, -1.1388383 , -1.13282014, -1.12766111, -1.11801458,
        -1.11315585, -1.11202727, -1.10573465, -1.10633907, -1.10164323,
        -1.09923572, -1.09870314, -1.0964029 , -1.09559775, -1.09294317],
       [-1.20182298, -1.18986148, -1.17271488, -1.16514141, -1.15608434,
        -1.14467673, -1.13649996, -1.13014992, -1.12468124, -1.11446911,
        -1.1092856 , -1.10802233, -1.1013158 , -1.10187355, -1.09684998,
        -1.09424223, -1.09361761, -1.09113968, -1.09024857, -1.08742052],
       [-1.20231363, -1.19006728, -1.17229746, -1.16451403, -1.15511841,
        -1.1432076 , -1.13465258, -1.12798558, -1.12221949, -1.11144827,
        -1.10594576, -1.10455232, -1.09743003, -1.09793991, -1.09258084,
        -1.08976315, -1.08903474, -1.08636315, -1.08536817, -1.08234472],
       [-1.20312542, -1.19062233, -1.17225232, -1.16428364, -1.15457093,
        -1.14217465, -1.13325812, -1.12628922, -1.12023864, -1.10891598,
        -1.10310203, -1.10158534, -1.09404832, -1.09451259, -1.08881418,
        -1.08578127, -1.08494221, -1.08206623, -1.08095502, -1.07772009],
       [-1.20423183, -1.19149811, -1.17254922, -1.16441857, -1.1544091 ,
        -1.14154418, -1.13228233, -1.12502644, -1.1187045 , -1.10683866,
        -1.1007219 , -1.09909038, -1.0911416 , -1.09156498, -1.08552625,
        -1.0822761 , -1.08132317, -1.07823609, -1.0770006 , -1.07354266],
       [-1.20560962, -1.1926696 , -1.17316149, -1.1648908 , -1.15460377,
        -1.14128613, -1.13169451, -1.12416615, -1.11758589, -1.10518533,
        -1.09877495, -1.09703799, -1.08868172, -1.08907061, -1.08269258,
        -1.07922557, -1.0781583 , -1.07485641, -1.07349194, -1.06980304],
       [-1.20723833, -1.19411466, -1.17406552, -1.16567547, -1.15512896,
        -1.1413736 , -1.13146703, -1.12368025, -1.11685446, -1.10392758,
        -1.09723301, -1.09540057, -1.08664185, -1.08700382, -1.08028891,
        -1.07660714, -1.07542706, -1.07190895, -1.07041333, -1.06648827],
       [-1.20909988, -1.19581373, -1.17524034, -1.16675043, -1.15596151,
        -1.14178251, -1.1315751 , -1.12354337, -1.11648448, -1.10303947,
        -1.09607017, -1.09415246, -1.08499679, -1.08534017, -1.07829176,
        -1.07439852, -1.07310866, -1.06937459, -1.0677476 , -1.06358331],
       [-1.21117828, -1.19774942, -1.17666728, -1.16809591, -1.15708065,
        -1.14249124, -1.13199637, -1.12373259, -1.11645259, -1.1024973 ,
        -1.09526263, -1.09326994, -1.08372306, -1.08405663, -1.07667871,
        -1.07257816, -1.07118259, -1.06723408, -1.06547694, -1.06107199]])

SQLFIDDLE