Solved

Table Formula SQL 2008

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

777 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