我需要关于子字符串的帮助。
该列guild_data
包含binary(4000)
.
我需要从 269 开始,每 40 和 15 长度获取每个值,直到结束。
例子:
SELECT DISTINCT
CONVERT(VARCHAR,substring(guild_data, 269, 15)) AS name,
CONVERT(VARCHAR,substring(guild_data, 309, 15)) AS name1,
CONVERT(VARCHAR,substring(guild_data, 349, 15)) AS name2,
CONVERT(VARCHAR,substring(guild_data, 389, 15)) AS name3,
-- so on until it gets till the end...
FROM
guild_data
有没有办法更有效地做到这一点?
我估计大约有 100 次重复...
269, 309, 349, 389, 429, 469, 509, 549, 589, 629, 669, 709, 749, 789, 829, 869, 909, 949, 989, 1029, 1069, 1109, 1149, 1189, 1229, 1269, 1309, 1349, 1389, 1429, 1469, 1509, 1549, 1589, 1629, 1669, 1709, 1749, 1789, 1829, 1869, 1909, 1949, 1989, 2029, 2069, 2109, 2149, 2189, 2229, 2269, 2309, 2349, 2389, 2429, 2469, 2509, 2549, 2589, 2629, 2669, 2709, 2749, 2789, 2829, 2869, 2909, 2949, 2989, 3029, 3069, 3109, 3149, 3189, 3229, 3269, 3309, 3349, 3389, 3429, 3469, 3509, 3549, 3589, 3629, 3669, 3709, 3749, 3789, 3829, 3869, 3909, 3949, 3989
谢谢你。
我正在寻找 T-SQL 查询。不过,我将在 PHP 脚本上使用它。
----edit---- 我们这里有这个脚本,它也可以工作。但是它太长了:)
CONVERT(VARCHAR,substring(guild_data, 269, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 309, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 349, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 389, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 429, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 469, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 509, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 549, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 589, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 629, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 669, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 709, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 749, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 789, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 829, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 869, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 909, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 949, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 989, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1029, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1069, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1109, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1149, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1189, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1229, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1269, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1309, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1349, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1389, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1429, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1469, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1509, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1549, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1589, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1629, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1669, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1709, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1749, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1789, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1829, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1869, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1909, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1949, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 1989, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2029, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2069, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2109, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2149, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2189, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2229, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2269, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2309, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2349, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2389, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2429, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2469, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2509, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2549, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2589, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2629, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2669, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2709, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2749, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2789, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2829, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2869, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2909, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2949, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 2989, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3029, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3069, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3109, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3149, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3189, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3229, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3269, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3309, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3349, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3389, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3429, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3469, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3509, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3549, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3589, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3629, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3669, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3709, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3749, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3789, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3829, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3869, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3909, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3949, 15)) AS glname,
CONVERT(VARCHAR,substring(guild_data, 3989, 15)) AS glname