If my application was designed to generate a "schedule" or list of dates, and I wanted to store those dates in a SQL server as an array, what SQL data type would I pick? ntext seems excessive, and I don't think date would work...any suggestions?

Recommended Answers

All 3 Replies

There is many options. If you want to save as DateTime, you will not be able to save as an array. Because only one value of dateTime can be stored into one cell.

You can choose a varChar - that means converting dateTime values into a string, and seperated them by some delimiter (like comma, or semi-colon, so you will be later when retreiving data be able to split them back and convert them to dateTime). I would go for this one.
In any case, if you want to save data as array, you will have to do some work-around.
Do what you want, but array as you know its not possible, you can seperate each data by some delimiter as explained.

I would just save all the dates on seperate entries with a common ID. I guess it depends on if you already have the database structure laid out, but if you are designing it from scratch that's what I'd do.

For example:

table 1 - Schedules
fields:
ID - PK
UserID - FK
Datetime
Comments

table 2 - Users
UserID - PK
Name
Comments

This way you can assosiate a user with their schedule, and with a simple

Select * from Schedules where UserID = myUserID

you can get the data for the array of dates.

Hey that's a clever idea skatamatic! I like it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.