1
2 -- ----------------------------------------------------
3 Declare @ Str Varchar ( 500 )
4 Set @ Str = ' Aaa, bbbx, eee, VV '
5 Select Len ( Replace ( @ Str , ' , ' , ' ,, ' )) - Len ( @ Str )
6
7
8 -- ----------------------------------------------------
9 Declare @ B Bit
10 Set @ B = 0
11 Select Substring (N ' No Yes ' , @ B + 1 , 1 )
12
13 -- ----------------------------------------------------
14 Declare @ IDS Varchar ( 50 )
15 Set @ IDS = ' 1, 3 '
16 Select * From Userinfo Where Charindex ( ' , ' + Rtrim (ID) + ' , ' , ' , ' + @ IDS + ' , ' ) > 0 -- Here, why do we need to add a comma before and after the string and ID?
17 -- ----------------------------------------------------
18 Select * Into T1 From Userinfo Where 1 = 0
19
20
21 Create Function F_split ( @ Str Varchar ( 8000 ), @ Strseprate Varchar ( 10 ))
22 Returns @ Temp Table ( Varchar ( 100 ))
23 As
24 Begin
25 Declare @ I Int
26 Set @ Str = Rtrim ( Ltrim ( @ Sourcesql ))
27 Set @ I = Charindex ( @ Strseprate , @ Str )
28 While @ I > = 1
29 Begin
30 Insert @ Temp Values ( Left ( @ Str , @ I - 1 ))
31 Set @ Str = Substring ( @ Str , @ I + 1 , Len ( @ Str ) - @ I ) -- Of course, you can also rewrite it to stuff here. You can try to rewrite it yourself.
32 Set @ I = Charindex ( @ Strseprate , @ Str )
33 End
34 If @ Sourcesql <> ' \ '
35 Insert @ Temp Values ( @ Str )
36 Return
37 End
38
39 -- Create a temporary table to generate a continuous ID.
40 Select * , Identity ( Int ) Nid Into # T From TB
41
42
43
44 Select * From DBO. f_split ( ' A: B: C: D: E ' , ' : ' )
45