divide a string

A

atse

Hi,
I have a string:
mystring="1234,5678,985,21544,55524,11264, ... ,"

How can I divide this string into
1234
5678
985
....
11264
....

And then delete records corresponding to these separated strings?

delete from mytable where id = '1234'
....
delete from mytable where id = '11264'
....

Thanks for any help.

Atse
 
D

dlbjr

mystring = "1234,5678,985,21544,55524,11264, ... ,"
arrData = Split(mystring ,",")
For intCount = 0 To UBound(arrData )
Delete arrData (intCount )
Next

'This is not the most efficient way.


-dlbjr

Discerning resolutions for the alms
 
D

Dan Brussee

Hi,
I have a string:
mystring="1234,5678,985,21544,55524,11264, ... ,"

How can I divide this string into
1234
5678
985
...
11264
...

And then delete records corresponding to these separated strings?

delete from mytable where id = '1234'
...
delete from mytable where id = '11264'
...

Thanks for any help.

Atse

If the id is a string, you will need to build a string of comma
delimited single quoted values.

Once you get the string, use the Split command to get an array of
values.

A(0) will = "1234"
A(1) will = "5678"
etc.

From here, cycle through the array appending to a string
t = t & "'" & a(x) & &"',"

Now use an SQL state ment like
"delete from mytable where id in (" & t & ")"

However, if your id values are numeric, you are basically there. Use
the same method generate the sql statement, substituting the original
string for t.
 
M

Manohar Kamath [MVP]

How about using the string in the SQL statement

DELETE FROM myTable WHERE ID IN(12,23,34,45)

Simpler than deleting one record at a time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,126
Messages
2,570,750
Members
47,308
Latest member
TorriLangr

Latest Threads

Top