Solved

Table Formula SQL 2008

Posted on 2014-02-24
3
175 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

896 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

15 Experts available now in Live!

Get 1:1 Help Now