Showing posts with label getdate. Show all posts
Showing posts with label getdate. Show all posts

Wednesday, March 21, 2012

How to setup default value using GETDATE?

Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at
table design windows for "OrderDate" using GETDATE(), but it does not work.
How do I use setup GETDATE default value for date type? Thanks

KaiOn Sun, 09 May 2004 03:39:07 GMT, kai wrote:

>Hi, All
> On Northwind database in SQL Server 2000, I try to setup default value at
>table design windows for "OrderDate" using GETDATE(), but it does not work.
>How do I use setup GETDATE default value for date type? Thanks
>Kai

Hi Kai,

ALTER TABLE MyTable
ADD DEFAULT GETDATE() FOR MyColumn
go

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||What do you mean exactly by 'it does not work'? Note that the default value
is used only when the column is omitted from the INSERT column list.

To add to Hugo's response, it's a good idea to name constraints explicitly
so that subsequent schema maintenance is easier:

ALTER TABLE MyTable
ADD CONSTRAINT DF_MyTable_MyColumn
DEFAULT GETDATE() FOR MyColumn

--
Hope this helps.

Dan Guzman
SQL Server MVP

"kai" <kailiang@.earthlink.net> wrote in message
news:vJhnc.3578$KE6.2982@.newsread3.news.atl.earthl ink.net...
> Hi, All
> On Northwind database in SQL Server 2000, I try to setup default value
at
> table design windows for "OrderDate" using GETDATE(), but it does not
work.
> How do I use setup GETDATE default value for date type? Thanks
> Kaisql

Monday, March 12, 2012

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

How to set the default value for a datetime culomn?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

If you want to insert current datetime by calling getdate() method, then it is possible in sql server everywhere. you can do like this;

insert into employee values (4,'John',25, getdate())

This will insert current datetime in the fourth column (in above example).

Please let me know if it answers your question.

Thanks

Sachin

|||

It is just getdate()

Not (getdate())

|||do u mean in sql werver or in asp.net|||Duh ,

He encapsulated it in an expression which started with a ( and so it ended with a ) It is correct. He did not just use the function getdate() as you indicated here.

Wednesday, March 7, 2012

how to set default value for datetime column in sql mobile?

I try to set a default value (getdate()) for a datetime culomn in sql mobile,
but got error when i insert record:

there was a syntax error in the date format. [expression = getdate()]

may be I can only set a exict date ?

I can repro the failure you are seeing. On Searching BOL for sql mobile, It says the following about the default definitions for columns.

DEFAULT Definitions

A column can have only one DEFAULT definition. This can contain constant values or constant functions.

You should post this to the SQL Server Everywhere/Mobile/CE Edition Technical Discussion forum.

Friday, February 24, 2012

How To Set Column Default Value to include Text AND GetDate() ?

GETDATE() works alone as default in a DateTime column, but:


1) How do you include current Date concatenated with text like:

- Column default Value = 'Submitted 2007-07-30 13:15:54.953'

2) is it possible to truncate that DateTime value (deleting the seconds 54.953)

- Final Column default Value = 'Submitted 2007-07-30 13:15'

Thinking Cast or convert but unsuccessful to date:

- 'Submitted ' + Cast(CHAR(16),GETDATE()) ?

I think the short answer here is, 'Yes'; it is just a matter of getting the format that you want. Here is an example:

Code Snippet

declare @.what table (aVc varchar(30) default('Submitted ' + left(convert(varchar, getdate(),120), 16)) )
insert into @.what default values

select * from @.what

/*
aVc
Submitted 2007-07-30 13:15
*/

Giving it another look you might want to try making your default

default('Submitted ' + convert(varchar(16), getdate(),120))

Might simplify the expression a bit.

|||Thanks Kent!