If you encounter such a problem during the write process, you need to process n data records in the library. Program Loop causes multiple accesses to the database
SQL Sever does not support array parameters. We tried two methods. Here we take the note as follows (the processing of a single piece of data is omitted, and # temp is used to display the result)
1. Use replace Create Table # temp
(
SS varchar ( 200 ) Not Null
)
Declare @ STR varchar ( 200 )
Declare @ result varchar ( 1000 )
Set @ Str = ' Aaa, BB, C, D, E, ffffff '
Set @ Result = ' Insert into # temp (SS) Select ''' + Replace (@ STR, ' , ' , ''' Union select ''' ) + ''''
Exec (@ result)
Select * From # temp
2. Use charindex and substring
Create Table # temp
(
SS varchar ( 200 ) Not Null
)
Declare @ STR varchar ( 200 )
Declare @ curr Int
Declare @ Prev Int
Set @ Str = ' Aaa, BB, C, D, E, ffffff '
Set @ Curr = 1
Set @ Prev = 1
While @ Prev < Len (@ Str)
Begin
Set @ Curr = Charindex ( ' , ' , @ STR, @ PREV)
If @ Curr > @ Prev
Insert # temp select substring (@ STR, @ Prev, @ curr - @ PREV)
Else
Begin
Insert # temp select substring (@ STR, @ Prev, Len (@ Str) - @ Prev + 1 )
Break
End
Set @ Prev = @ Curr + 1
End
Select * From # temp