Solved

Table Formula SQL 2008

Posted on 2014-02-24
3
174 Views
Last Modified: 2014-03-04
In the design of a table in SQL 2008 there is the ability to add a function to a column of data as its loaded. I have a date column (data type is date) and I want to subtract a day from the date column source file (which is excel). I thought I could simply use a Data Add function of DateAdd(day, -1, Date). However when I insert that and try to save the table I it states that it is an error.
Please advise, thanks
0
Comment
Question by:SeTech
  • 2
3 Comments
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 39882236
Please post your SQL and the error you get.
0
 

Author Comment

by:SeTech
ID: 39882243
code: DateAdd (day, -1, Date)

Statement: "Error validating the formula for Column Date"
0
 
LVL 12

Accepted Solution

by:
Harish Varghese earned 500 total points
ID: 39882289
Are you talking about computed column in table? If so, you cannot refer to same column in a computed column expression. For example, below code would work:
CREATE Table RightTable (ID int,
    OriginalDate date,
    ComputedDate as DateAdd(dd, -1, OriginalDate)
)

but below definition will not work:
CREATE Table WrongTable (ID int,
    OriginalDate date,
    ComputedDate as DateAdd(dd, -1, ComputedDate)
)

-Harish
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now