Reputation: 5539
I need a query which would append data to the existing value of a cell. For Eg: Current Value of Cell: "2013-03-15" Value after Update: "2013-03-15,2013-03-25"
Is it even possible? Note: i do not want to update the entire column at once. Only cell.
Upvotes: 2
Views: 15316
Reputation: 4643
If assuming you are using DateTime DataType, then you must:
Create another table, for example RequestDateTime:
Create table REQUEST_DATE_TIME(
REQUEST_ID VARCHAR(10), -- or whatever PK your main table use
Request_date DATETIME
)
Then add relation between the two tables.
However when you use varchar(n) data type, you can do a simple as:
Update table set DateTimeCell = DateTimeCell + CAST(@VALUE AS VARCHAR)
Maybe you can get better answer if you tell what you are trying to achieve.
Upvotes: 1
Reputation: 8937
Don't do like that. Create another column, like newDate and store your new value there. When you use dates you have to store them, like dates, not like text. Or you can store your dates in single column with some kind on foreign key to you referenced table of students.
Upvotes: 0
Reputation: 9583
Try something like this:
UPDATE tblMyTable
SET MyCell = MyCell + ',' + 'My Other Value'
Or
UPDATE tblMyTable
SET MyCell = MyCell + ',' + @MyParameter
Bear in mind, the type of MyCell
will need to be text based, for instance: nvarchar(256)
etc...
Upvotes: 3
Reputation: 10555
It is not possible if you are using Date. Use Text data type.
First, read the data from database of a corresponding cell and then append your data by String concatenation.
Next, Update the cell
while (myReader.Read())
{
String d1=myReader["dat"].ToString());
}
String d2=d1+","+your_variable or data
The update it
Upvotes: 0