Showing posts with label formula. Show all posts
Showing posts with label formula. Show all posts

Tuesday, March 27, 2012

Automaticaly popluating Current Date in a Db Field

Hi,
I have a field in he db called LogDate. I have made it a timestamp type. Is
there a formula or a default value i can set for this field in the table
design view so that everytime a record is added, this field is automaticalll
y
populated with teh current date?
Thanks
--
pmudDid youy read anything in the SQL Server documentation about the timestamp
datatype? In spite of its poor name, it has nothing to do with date or
time.
Try the following instead:
CREATE TABLE dbo.MyStuff
(
StuffName NVARCHAR(32) PRIMARY KEY,
CreatedDate SMALLDATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
GO
INSERT dbo.MyStuff(StuffName) SELECT N'foo';
WAITFOR DELAY '00:00:01';
INSERT dbo.MyStuff(StuffName) SELECT N'bar';
GO
SELECT StuffName, CreatedDate FROM dbo.MyStuff;
DROP TABLE dbo.MyStuff;
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:19D4287C-0ED6-401A-AE61-9B0F0FB5EDAB@.microsoft.com...
> Hi,
> I have a field in he db called LogDate. I have made it a timestamp type.
> Is
> there a formula or a default value i can set for this field in the table
> design view so that everytime a record is added, this field is
> automaticallly
> populated with teh current date?
> Thanks
> --
> pmud|||First, you need to define the field as a datetime data type. The timestamp
data type is used for concurrency checking using optomistic locking and does
not represent an actual date and time.
I typically use a default value of CURRENT_TIMESTAMP to put the current date
and time in a field.
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:19D4287C-0ED6-401A-AE61-9B0F0FB5EDAB@.microsoft.com...
> Hi,
> I have a field in he db called LogDate. I have made it a timestamp type.
> Is
> there a formula or a default value i can set for this field in the table
> design view so that everytime a record is added, this field is
> automaticallly
> populated with teh current date?
> Thanks
> --
> pmud|||Hi Aaron and Geoff,
Thanks for the reply. I made it a datetiem, and in the default value, I used
the function, GetDate() , and it worked. :)
pmud
"Geoff N. Hiten" wrote:

> First, you need to define the field as a datetime data type. The timestam
p
> data type is used for concurrency checking using optomistic locking and do
es
> not represent an actual date and time.
> I typically use a default value of CURRENT_TIMESTAMP to put the current da
te
> and time in a field.
> --
> Geoff N. Hiten
> Senior Database Administrator
> Microsoft SQL Server MVP
>
> "pmud" <pmud@.discussions.microsoft.com> wrote in message
> news:19D4287C-0ED6-401A-AE61-9B0F0FB5EDAB@.microsoft.com...
>
>|||Good. Just FYI, getdate() is the T-SQL specific function. The ANSI
(cross-platform) standard is CURRENT_TIMESTAMP. They are absolutely
equivalent for SQL Server, except using getdate() will provoke the "Wrath of
CELKO" (tm). :)
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"pmud" <pmud@.discussions.microsoft.com> wrote in message
news:996A9A56-738B-4C38-8BE3-F89BBB68BBD2@.microsoft.com...
> Hi Aaron and Geoff,
> Thanks for the reply. I made it a datetiem, and in the default value, I
> used
> the function, GetDate() , and it worked. :)
>
> --
> pmud
>
> "Geoff N. Hiten" wrote:
>|||Hi geoff,
I had saved my tiable with GetDate() as the default value adn data type as
datetime. Now I changed teh default value to CURRETNT_TIMESTAMP as suggested
by you, but when i click on Save , the default value automatically changes t
o
GetDate() . What do you suggest for this? Can this be a problem?
Thanks
--
pmud
"Geoff N. Hiten" wrote:

> Good. Just FYI, getdate() is the T-SQL specific function. The ANSI
> (cross-platform) standard is CURRENT_TIMESTAMP. They are absolutely
> equivalent for SQL Server, except using getdate() will provoke the "Wrath
of
> CELKO" (tm). :)
> --
> Geoff N. Hiten
> Senior Database Administrator
> Microsoft SQL Server MVP
>
>
> "pmud" <pmud@.discussions.microsoft.com> wrote in message
> news:996A9A56-738B-4C38-8BE3-F89BBB68BBD2@.microsoft.com...
>
>|||> I had saved my tiable with GetDate() as the default value adn data type as
> datetime. Now I changed teh default value to CURRETNT_TIMESTAMP as
> suggested
> by you, but when i click on Save , the default value automatically changes
> to
> GetDate() . What do you suggest for this? Can this be a problem?
This is Enterprise Manager playing tricks on you. My suggestion is to stop
using Enterprise Manager for these things, use Query Analyzer and learn the
T-SQL equivalent(s).
A|||Ok. Thanks Aaron. I will try through Quey Analyzer.
--
pmud
"Aaron Bertrand [SQL Server MVP]" wrote:

> This is Enterprise Manager playing tricks on you. My suggestion is to sto
p
> using Enterprise Manager for these things, use Query Analyzer and learn th
e
> T-SQL equivalent(s).
> A
>
>|||> Ok. Thanks Aaron. I will try through Quey Analyzer.
If you use Enterprise Manager to "verify" be aware that it may still want to
convert CURRENT_TIMESTAMP to GETDATE().

Tuesday, March 20, 2012

Automatic recalculation without having to change formula

I have a worksheet that calculates the last 6 months of information. Is there a formula that will automatically change the cell range to the last 6 columns once you have entered another column? I need to keep the previous information. I usually add the new column, hide the oldest column, and then change the cell range manually. This leaves room for user errors and is a great big pain in the badonky donk. I would appreciate any help.I am wondering if you are talking about Reporting Services, as you are takling about cell ranges ?

Jens K. Suessmeyer

http://www.sqlserver2005.de
|||

I really have no idea at all. I will give you an example.

6 month total Jan Feb Mar Apr May Jun July Aug

Kim 4639.00 492.00 875.00 921.00 785.00 567.00 924.00 567.00 824.00

Each month I add the new information to the spreatsheet. Now when I enter the totals for August I want Excel to automaticaly grab the last 6 months of information. So when I Enter August it will automaticaly drop off the February totals and pick up the newly entered August totals. I don't know if this is possible, but it would be really nice if Excel could do this. Right now I have to manually change the formula for each person. Each person has 4 different 6 month totals to calculate. For me this is not so bad because there are only 2 employees in our office, but I have received emails from other offices that have quite a few employees and this would be helpful. It would also reduce operator error.

A Greniger

|||Group your values to the month, use a matrix to display the data and put the month on the horizontal axis, and the user (seems in your case) on the vertical one.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

Monday, March 19, 2012

Automatic recalculation without having to change formula

I have a worksheet that calculates the last 6 months of information. Is there a formula that will automatically change the cell range to the last 6 columns once you have entered another column? I need to keep the previous information. I usually add the new column, hide the oldest column, and then change the cell range manually. This leaves room for user errors and is a great big pain in the badonky donk. I would appreciate any help.I am wondering if you are talking about Reporting Services, as you are takling about cell ranges ?

Jens K. Suessmeyer

http://www.sqlserver2005.de
|||

I really have no idea at all. I will give you an example.

6 month total Jan Feb Mar Apr May Jun July Aug

Kim 4639.00 492.00 875.00 921.00 785.00 567.00 924.00 567.00 824.00

Each month I add the new information to the spreatsheet. Now when I enter the totals for August I want Excel to automaticaly grab the last 6 months of information. So when I Enter August it will automaticaly drop off the February totals and pick up the newly entered August totals. I don't know if this is possible, but it would be really nice if Excel could do this. Right now I have to manually change the formula for each person. Each person has 4 different 6 month totals to calculate. For me this is not so bad because there are only 2 employees in our office, but I have received emails from other offices that have quite a few employees and this would be helpful. It would also reduce operator error.

A Greniger

|||Group your values to the month, use a matrix to display the data and put the month on the horizontal axis, and the user (seems in your case) on the vertical one.

Jens K. Suessmeyer.

http://www.sqlserver2005.de