declare
@strtrannote
nvarchar
(
100
);
declare
@strlocation
nvarchar
(
100
);
declare
@tempstr
nvarchar
(
100
);
set
@strtrannote
=
'
a*b*
'
;
set
@strlocation
=
'
1*2*
'
;
set
@tempstr
=
@strlocation
DECLARE
@Index
int
;
DECLARE
@Left
nvarchar
(
50
);
WHILE
CHARINDEX
(
'
*
'
,
@strtrannote
)
>
0
--
返回字符串中指定表达式的起始位置
BEGIN
SELECT
@Index
=
CHARINDEX
(
'
*
'
,
@strtrannote
);
--
返回字符串中第一个"&"的起始位置
SELECT
@Left
=
LEFT
(
@strtrannote
,
@Index
-
1
);
--
从左边开始,取得字符串左边指定个数的字符(第一个值)
--
update TranNote set packlist_id=@packlist_id where TranNotekey=@LEFT and website=@website;
DECLARE
@Index2
int
;
DECLARE
@Left2
nvarchar
(
50
);
set
@strlocation
=
@tempstr
WHILE
CHARINDEX
(
'
*
'
,
@strlocation
)
>
0
--
返回字符串中指定表达式的起始位置
BEGIN
SELECT
@Index2
=
CHARINDEX
(
'
*
'
,
@strlocation
);
--
返回字符串中第一个"&"的起始位置
SELECT
@Left2
=
LEFT
(
@strlocation
,
@Index2
-
1
);
--
从左边开始,取得字符串左边指定个数的字符(第一个值)
print
(
@left
);
print
(
@left2
);
SELECT
@strlocation
=
REPLACE
(
@strlocation
,
@Left2
+
'
*
'
,
''
);
--
将左边已经取出的部分替换为空
END
SELECT
@strtrannote
=
REPLACE
(
@strtrannote
,
@Left
+
'
*
'
,
''
);
--
将左边已经取出的部分替换为空
END
显示结果:
a 1 a 2 b 1 b 2
转载于:https://www.cnblogs.com/lfzwenzhu/archive/2008/11/13/1332905.html
转载请注明原文地址: https://win8.8miu.com/read-1558967.html