Link to home
Start Free TrialLog in
Avatar of Cartillo
CartilloFlag for Malaysia

asked on

Modify SQL table

Hi Experts,

Need Experts help. Is that a way to modify the SQL data without recreate the whole table? I'm intended to add a new formula but  the server not allowing me to do so. I've attached the print screen of the alert message for Experts perusal.  

Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

>> I'm intended to add a new formula

Hope you are trying to add a derived column and you can use the below syntax to achieve it:

alter table ur_table_name add a as b + c

where a is the new column which you are trying to add and replace b+c with the expression/formula.
Avatar of Cartillo


Hi rrjegan17,

Thanks for the guide. Attached the code that has been used to create total duration, however it shows as "build" error. Hope you can guide me to fix this error.
Imports MyCompany.Data
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Linq
Imports System.Text.RegularExpressions
Imports System.Web

Namespace Rules
    Partial Public Class DataBusinessRules
        Inherits MyCompany.Rules.SharedBusinessRules
        <ControllerAction("Data", "Calculate", "Total_Duration")>  _
        Public Sub CalculateData(ByVal data_ID As Nullable(Of Integer), ByVal [date] As Nullable(Of DateTime), ByVal task As String, ByVal timeIN As Nullable(Of System.TimeSpan), ByVal timeOUT As Nullable(Of System.TimeSpan), ByVal total_Duration As Nullable(Of System.TimeSpan))
            UpdateFieldValue("Total_Duration", (datediff(HOUR,[TimeIN],[TimeOUT])))
        End Sub
    End Class
End Namespace

Open in new window

With this "alter table ur_table_name add a as b + c" there is no issue.

Please check datatype of both fields.
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the advice rrjegan17.