Modify SQL table

Cartillo
Cartillo used Ask the Experts™
on
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.  


image1.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018

Commented:
>> 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.

Author

Commented:
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

Alpesh PatelSolution Architect at TCS (SAFe®Agilist, TOGAF® Foundation, PSM I®, MCP, MCSD)

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

Please check datatype of both fields.
SQL Server DBA & Architect, EE Solution Guide
Awarded 2009
Distinguished Expert 2018
Commented:
seems like you are trying to create expressions/ formula at front end.
If you could tell the exact formula, we would be able to help you from the SQL Server level..

Else you need to include this question into VB zone so that front end application experts can help you out..

Author

Commented:
Thanks for the advice rrjegan17.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial