We help IT Professionals succeed at work.

How to pull multiple values from a single cell

221 Views
Last Modified: 2013-11-26
I have a VB form that writes multiple dates to a column in a SQL Server 2005 tabIe. I would like to be able to pull out each individual date and write a new record to a seperate table and duplicate the additional information in that record. I assume I need to create some sort of split function but am not sure how to accomplish this.
for example:
Name       |   Dates
john Doe  | 12/12/2007,12/13/2007, 12/14/2007,

I would like to have the records inserted into a new table..
Name        |  Date
John Doe  | 12/12/2007
John Doe  | 12/13/2007
John Doe  | 12/14/2007

Any help would be appreciated.
Comment
Watch Question

Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Here you'll find a split-function

Dim Dates as string = "12/12/2007,12/13/2007, 12/14/2007"
Dim myDates As String() = Nothing
myDates = values.Dates (",")

dim s as string
For Each s In myDates
   ' Add your code here to insert the data into the database
   Console.WriteLine(s)
Next s
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
D-bass,

Small change to Dhaest code to work fine:

Dim Dates as string = "12/12/2007,12/13/2007, 12/14/2007"
Dim myDates As String() = Nothing
 myDates = Dates.Split(",")  ' <-- CHANGE

dim s as string
For Each s In myDates
   ' Add your code here to insert the data into the database
   Console.WriteLine(s)
Next s

Author

Commented:
I am looking for a solution on the SQL side, after the individual record has been inserted int the table. I would like to run a procedure to take the dates field and then create several records off of that field based on the number of dates that were entered. so if a given recrod from the first table has three date values seperated with commoas, I need to create 3 seperate records for each date. Would a cursor be used in this situation. Does this make sense? I may not be explaining it well.

Thanks
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I am still having trouble. I cannot get the first two suggestions to work in the VB form. They are still inserting all of the date values into one record. I cannot get the insert statmeent to work with the last suggestion above.

Thanks to all who have responded. Any other suggestions that may help?

Author

Commented:
derekkromm,
I did get your last suggestion to work. thnaks for your help!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.