Board index » Web Programming » pulling stuff from comma-delimited field

pulling stuff from comma-delimited field

Web Programming319
I have a page where I allow the user to select one or more names of

employees to send an email to, which is sent automatically when the form is

submitted. I have a field called EmailSentTo, and if you sent it to Joe

Smith, then it stores the employee's number, 200, which is the PK of the

Employee table.



And there is, of course, another page which displays all the information

from that form I just submitted, so I want to display this new thing I

added, the name of the person I sent an email to. So far, no problem.



The thing gets complicated when I choose to send the email to more than one

person. In that case, I select Joe Smith and Mary Jones, and it enters

"200,100" into the field. A comma-delimited set of empoloyee IDs.



I realize that in order to display this, I would need some sort of loop, but

I'm not sure about how to do this. I can do a loop which pulls different

records from a table, but this is pulling several things from one field of

one record. Anyone got any sample code?



(BTW, I know that this is essentially a one-to-many, and I should simply

break it down to another table, but I was trying to avoid that. But I will

if that's the best thing to do)


-
 

Re:pulling stuff from comma-delimited field

I am not sure I understand you correctly,



but you can use the split() function to split a string "100,200, 300" into

an array .

Or if you use that in a select statement use can use

select * from table where EmployeeID in (100,200,300)

then you can loop through that...



HTH



"middletree" <middletree@htomail.com>wrote in message

Quote
I have a page where I allow the user to select one or more names of

employees to send an email to, which is sent automatically when the form

is

submitted. I have a field called EmailSentTo, and if you sent it to Joe

Smith, then it stores the employee's number, 200, which is the PK of the

Employee table.



And there is, of course, another page which displays all the information

from that form I just submitted, so I want to display this new thing I

added, the name of the person I sent an email to. So far, no problem.



The thing gets complicated when I choose to send the email to more than

one

person. In that case, I select Joe Smith and Mary Jones, and it enters

"200,100" into the field. A comma-delimited set of empoloyee IDs.



I realize that in order to display this, I would need some sort of loop,

but

I'm not sure about how to do this. I can do a loop which pulls different

records from a table, but this is pulling several things from one field of

one record. Anyone got any sample code?



(BTW, I know that this is essentially a one-to-many, and I should simply

break it down to another table, but I was trying to avoid that. But I will

if that's the best thing to do)









-

Re:pulling stuff from comma-delimited field

sIDlist = "200,100"

aIDarray = split(sIDlist, ",")

for i = 0 to ubound(aIDarray)

nThisID = aIDarray(i)

DoSomethingWith(nThisID)

next



or...



sIDlist = "200,100"

sSQL = "Select field1, field2 from table1 where ID in (" & sIDlist & ")"

set rs = conn.Execute(sSQL)

do until rs.EOF

DoWhateverWith(rs("field1"))

rs.MoveNext

loop



"middletree" <middletree@htomail.com>wrote in message

Quote
I have a page where I allow the user to select one or more names of

employees to send an email to, which is sent automatically when the

form is

submitted. I have a field called EmailSentTo, and if you sent it to

Joe

Smith, then it stores the employee's number, 200, which is the PK of

the

Employee table.



And there is, of course, another page which displays all the

information

from that form I just submitted, so I want to display this new thing I

added, the name of the person I sent an email to. So far, no problem.



The thing gets complicated when I choose to send the email to more

than one

person. In that case, I select Joe Smith and Mary Jones, and it enters

"200,100" into the field. A comma-delimited set of empoloyee IDs.



I realize that in order to display this, I would need some sort of

loop, but

I'm not sure about how to do this. I can do a loop which pulls

different

records from a table, but this is pulling several things from one

field of

one record. Anyone got any sample code?



(BTW, I know that this is essentially a one-to-many, and I should

simply

break it down to another table, but I was trying to avoid that. But I

will

if that's the best thing to do)





-

Re:pulling stuff from comma-delimited field

Don't really know much about arrays, but I think I can work with this.

Thanks.





"Kris Eiben" <eibenkthisisforspammers@yahoo.com>wrote in message

Quote
sIDlist = "200,100"

aIDarray = split(sIDlist, ",")

for i = 0 to ubound(aIDarray)

nThisID = aIDarray(i)

DoSomethingWith(nThisID)

next



or...



sIDlist = "200,100"

sSQL = "Select field1, field2 from table1 where ID in (" & sIDlist & ")"

set rs = conn.Execute(sSQL)

do until rs.EOF

DoWhateverWith(rs("field1"))

rs.MoveNext

loop



"middletree" <middletree@htomail.com>wrote in message

news:er0y7RaYDHA.2328@TK2MSFTNGP12.phx.gbl...

>I have a page where I allow the user to select one or more names of

>employees to send an email to, which is sent automatically when the

form is

>submitted. I have a field called EmailSentTo, and if you sent it to

Joe

>Smith, then it stores the employee's number, 200, which is the PK of

the

>Employee table.

>

>And there is, of course, another page which displays all the

information

>from that form I just submitted, so I want to display this new thing I

>added, the name of the person I sent an email to. So far, no problem.

>

>The thing gets complicated when I choose to send the email to more

than one

>person. In that case, I select Joe Smith and Mary Jones, and it enters

>"200,100" into the field. A comma-delimited set of empoloyee IDs.

>

>I realize that in order to display this, I would need some sort of

loop, but

>I'm not sure about how to do this. I can do a loop which pulls

different

>records from a table, but this is pulling several things from one

field of

>one record. Anyone got any sample code?

>

>(BTW, I know that this is essentially a one-to-many, and I should

simply

>break it down to another table, but I was trying to avoid that. But I

will

>if that's the best thing to do)









-