?
Solved

Table Formula SQL 2008

Posted on 2014-02-24
3
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

800 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