Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

Friday, February 24, 2012

Default values for datetime parameters

Hi all,

I have a report that needs a to-date and a from-date as input. I would like them to be set to today by default.

I have set the data type for both parameters to DateTime and the default value as "Non-queried" = Today()

This does fill in the dates with today, but I cannot change the value in the fields, until the report has been generated once. I just want the date to be equal to today since 90% of the time that is what my users wants to see - but I want to give the last 10% the chance to change the date without having to generate the report first.

The date-fields are locked until some of the other parameters are filled in... It makes no sense really.

Hope you can help me here :-D

-- Heidi, Denmark

I have the following report parameters set that generate default From & To dates as the previous months 1st & Last Day. Both Available Parameters & Default Parameters are set to "Non-Queried"

The third parameter (groupid) defaults to a Null value but user can choose from a list of valid values.

When I deploy this report, the user can change the From & To dates without first running the report.

I'll attach the parameters XML

<ReportParameters>

<ReportParameter Name="startdate">

<DataType>DateTime</DataType>

<DefaultValue>

<Values>

<Value>=dateadd("m",-1,dateadd("d",-day(today)+1,today))</Value>

</Values>

</DefaultValue>

<Prompt>Select From Date</Prompt>

</ReportParameter>

<ReportParameter Name="enddate">

<DataType>DateTime</DataType>

<DefaultValue>

<Values>

<Value>=dateadd("d",-day(today),today)</Value>

</Values>

</DefaultValue>

<Prompt>Select To Date</Prompt>

</ReportParameter>

<ReportParameter Name="groupid">

<DataType>String</DataType>

<Prompt>Select Hierarchy Group</Prompt>

<ValidValues>

<DataSetReference>

<DataSetName>H_Groups</DataSetName>

<ValueField>id</ValueField>

<LabelField>List</LabelField>

</DataSetReference>

</ValidValues>

</ReportParameter>

</ReportParameters>

Does this help at all?

|||

Hi,

I've tried setting the dates like you do, but that doesn't help me. The user still isn't able to change the date values.

I have 6 parameters:

"Product" e.g. Ham (character)

"Batch" e.g. 121434 (character)

"From date" (datetime)

"From time" 05:00 (character)

"To date" e.g. (datetime)

"To time" e.g. 11:30 (character)

I only have default values for the date fields. The user cannot change the date values until he has entered something in the other parameters. It is like the date fields are disabled somehow and the default date isn't even displayed to the user (the field is simply grey...)

I suspect that it is because I use built-in functions instead of data from a query (I've tried making an sql selecting today, but I cannot really get that to work - problems with the formatting) :-S

|||

Heidi Christiansen wrote:

I suspect that it is because I use built-in functions instead of data from a query (I've tried making an sql selecting today, but I cannot really get that to work - problems with the formatting) :-S

I'm using built-in functions as well, so I don't think that's it.

Try making your date parameters the first ones to be chosen. I think this fixes it for you, although I don't really understand why this should be the case. I suspect it would be "by design"

|||

LOL

That helped... strange design decisions....

Thank you for your help :-D

default values

Is it possible to set report parameter of type datetime on current date in case when user don't specify value?
Thx.Yes you can and it's dead easy.
In the Report Parameters dialog, in the Default Values section at the borrom of the form, select Non-queried and use the following expression:
=Globals!ExecutionTime
That'll insert the exact date and time of when the report is run as a default value if one isn't entered.
DF
"AG, NLB d.d." wrote:
> Is it possible to set report parameter of type datetime on current date in case when user don't specify value?
> Thx.|||is it possible to make yesterday as default value?
>--Original Message--
>Yes you can and it's dead easy.
>In the Report Parameters dialog, in the Default Values
section at the borrom of the form, select Non-queried and
use the following expression:
>=Globals!ExecutionTime
>That'll insert the exact date and time of when the report
is run as a default value if one isn't entered.
>DF
>"AG, NLB d.d." wrote:
>> Is it possible to set report parameter of type datetime
on current date in case when user don't specify value?
>> Thx.
>.
>

default value of DateTime field - Now

Hello,
Can I simply set the default value of a dateTime field with the date and time that the record was created?yes, you can|||Use GetDate() function as default value...

Sunday, February 19, 2012

default value in datetime column

hi, i was wondering how to set default value in the datetime column of the database so that it will enter current date and time if one is not provided when a row is populated. is there a store procedure to do this? or built-in function?

mp

If you go to Modify view of the table in either Enterprise Manager or SQL Server Management Studio and select that database field, there should be a property where you can specify the default value. Enter GETDATE() as the default value.|||

There are 2 ways to add default value as Today's Date

1) Using QueryAnalyzer

alter table <TableName>
add <ColumnName> DateTime default getdate()

//This will add one column with Default value as Today's date. If you want to add to existing column...2)

2) go to Enterprise Manager, ... , select your table, Right click, go to Design Table and open...

place the mouse cusor in which column you want to put default value, When you place the mouse cursor bottom of this you will see Columns Tab-->Default value TextBox put getdate() and Save . Now insert any row it will automatically enters to days date

|||

thanks, just what i needed!

Happy New Year!!!

mp

Default Value in Date Field

I am trying to put today's date into a DateTime field in a table. Is there
something I can put in the Default Value property of that field to do this?
I used to do this in Access, but can't figure it out in SQL Server.
Thanks in advance,
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health SystemExample:
use northwind
go
create table dbo.t (
colA datetime not null constraint df_colA default (getdate())
)
go
insert into dbo.t default values
go
select * from dbo.t
go
drop table dbo.t
go
AMB
"chuckdfoster" wrote:

> I am trying to put today's date into a DateTime field in a table. Is ther
e
> something I can put in the Default Value property of that field to do this
?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>
>|||You can put GETDATE() in the Default Value property.
Jacco Schalkwijk
SQL Server MVP
"chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
>I am trying to put today's date into a DateTime field in a table. Is there
> something I can put in the Default Value property of that field to do
> this?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>|||create table mytable (
a int,
b smalldatetime default getdate()
)
insert into mytable (a) values (1)
select * from mytable
a | b
___________________
1 | 2005-04-25 15:36:00
"chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
>I am trying to put today's date into a DateTime field in a table. Is there
> something I can put in the Default Value property of that field to do
> this?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>|||Hi
Use GETDATE() : For current systemdate and
GETUTCDATE() : for current GMT
Aneesh
"chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
> I am trying to put today's date into a DateTime field in a table. Is
there
> something I can put in the Default Value property of that field to do
this?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>|||Thank you! Those where exactly what I needed!
Chuck Foster
"Kasper Birch Olsen" <kasper@.nospam.com> wrote in message
news:%23g%23JEwZSFHA.2348@.TK2MSFTNGP09.phx.gbl...
> create table mytable (
> a int,
> b smalldatetime default getdate()
> )
> insert into mytable (a) values (1)
> select * from mytable
> a | b
> ___________________
> 1 | 2005-04-25 15:36:00
>
> "chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
> news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
there
>

default value for todays date and time

I have a column 'date and time', of type datetime.
I'm using MS VB Express - and am trying to enter a default value for
the column of today's date and time.
I cant find anything to enter in the 'default' property of the column
that will return todays date and time.
please help.
gary.
try either the function getdate() or CURRENT_TIMESTAMP
<garyusenet@.myway.com> wrote in message
news:1130144997.367325.64910@.f14g2000cwb.googlegro ups.com...
>I have a column 'date and time', of type datetime.
>
> I'm using MS VB Express - and am trying to enter a default value for
> the column of today's date and time.
>
> I cant find anything to enter in the 'default' property of the column
> that will return todays date and time.
>
> please help.
>
> gary.
>

default value for todays date and time

I have a column 'date and time', of type datetime.
I'm using MS VB Express - and am trying to enter a default value for
the column of today's date and time.
I cant find anything to enter in the 'default' property of the column
that will return todays date and time.
please help.
gary.try either the function getdate() or CURRENT_TIMESTAMP
<garyusenet@.myway.com> wrote in message
news:1130144997.367325.64910@.f14g2000cwb.googlegroups.com...
>I have a column 'date and time', of type datetime.
>
> I'm using MS VB Express - and am trying to enter a default value for
> the column of today's date and time.
>
> I cant find anything to enter in the 'default' property of the column
> that will return todays date and time.
>
> please help.
>
> gary.
>

default value for todays date and time

I have a column 'date and time', of type datetime.
I'm using MS VB Express - and am trying to enter a default value for
the column of today's date and time.
I cant find anything to enter in the 'default' property of the column
that will return todays date and time.
please help.
gary.try either the function getdate() or CURRENT_TIMESTAMP
<garyusenet@.myway.com> wrote in message
news:1130144997.367325.64910@.f14g2000cwb.googlegroups.com...
>I have a column 'date and time', of type datetime.
>
> I'm using MS VB Express - and am trying to enter a default value for
> the column of today's date and time.
>
> I cant find anything to enter in the 'default' property of the column
> that will return todays date and time.
>
> please help.
>
> gary.
>

Default value for Datetime column

Hi
I am using 01/01/1753 to define the "Empty Date" for my datetime fields.
My tables have several columns that are defined as datetime fields which
need to default to the empty date that I have chosen.
I type in 01/01/1753 as the default value of the table designer, however
when I insert a new line into any of the tables, the value that gets
inserted is 01/01/1900.
Does anyone know why this is happening? I am assuming that I have some
configuration value set incorrectly.
I realise that I could simply use 1900 as the empty date. I could also
include the field and a value in the insert statement, but that isn't the
point. I'd rather know why the system behaves like this.
Hope someone can help
Thanks in anticipationDATETIME is just that. It is not date or time, it is both. If you set the
default value of 1753-01-01 then it is 1753-01-01 12:00:00.000 AM if no
value is inserted. If you enter a date or a time, *that* value determines
the other part. If you enter a time only in Query Analyzer, you get
1900-01-01 hh:mm:ss, if you do it in Enterprise Manager, you get 1899-12-31
hh:mm:ss. A value you enter overrides the entire value, even if you only
specify a portion. You can't say the date is x if I enter a time of y. If
you want a specific date to go along with your time, enter that date as
well. You should handle this in a stored procedure so that it is
consistent.
http://www.aspfaq.com/2206
http://www.aspfaq.com/2455
"Mark_S" <Mark_S@.nospam.nospam> wrote in message
news:%23$GRC7$1FHA.2056@.TK2MSFTNGP10.phx.gbl...
> Hi
>
> I am using 01/01/1753 to define the "Empty Date" for my datetime fields.
>
> My tables have several columns that are defined as datetime fields which
> need to default to the empty date that I have chosen.
>
> I type in 01/01/1753 as the default value of the table designer, however
> when I insert a new line into any of the tables, the value that gets
> inserted is 01/01/1900.
>
> Does anyone know why this is happening? I am assuming that I have some
> configuration value set incorrectly.
>
> I realise that I could simply use 1900 as the empty date. I could also
> include the field and a value in the insert statement, but that isn't the
> point. I'd rather know why the system behaves like this.
>
> Hope someone can help
>
> Thanks in anticipation
>|||>> I am using 01/01/1753 to define the "Empty Date" for my datetime fields [sic].
<<
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files. One of the MANY differences in
fields and columns is that a field can be missing or empty while a
column cannot.
Next, the proper format for dates in SQL is '1753-01-01' as per the
ISO-11179 Standards.
That has to do with the internal representation of DATETIME data types
in SQL Server. And Great Britain and its colonies went to the
Gregorian (Common Era) calendar in 1752, nobody started on
'1753-01-01' as far as I can tell.
No, you cannot. That is an integer and not a temporal data element at
all. Temporal data types, like all other SQL data types, can have a
NULL value. You can also add a DEFAULT CURRENT_TIMESTAMP or
DEFAULT '1753-01-01' clause to the DDL.
Exactly what are you trying to do?|||> Exactly what are you trying to do?
Sounds like when he enters a "datetime" value, like '4:30 PM', he wants the
date that goes with that to be 1753-01-01.
A|||Mark_S (Mark_S@.nospam.nospam) writes:
> I am using 01/01/1753 to define the "Empty Date" for my datetime fields.
Why not use NULL?
There are those who think NULL are evil, but just face it. Any in-band
value that is used to mean "no value" is going to cause problem. If
nothing else, there can be confusion about which that value is.
(Although I will have to admit having used 17530101, in one place in our
system. I had a need to distinguish between "it has always been this
way" (which is 17530101) and "it has never been this way" (which is NULL).)

> I type in 01/01/1753 as the default value of the table designer, however
> when I insert a new line into any of the tables, the value that gets
> inserted is 01/01/1900.
When you specify a string for a datetime value in SQL Server, all parts
have a default value which is applied. So an empty string, results in
1900-01-01 00.00.00:000.
Since you get this value, you are apparently explicitly specifying a value.
Had you specified a NULL value, you would have gotten a NULL (or a NOT
NULL violation). The default value is only used when nothing at all
is specified.
This script illustrates:
CREATE TABLE datedemo (a int NOT NULL,
d datetime NULL DEFAULT '17530101')
go
INSERT datedemo (a) VALUES (1)
INSERT datedemo (a, d) VALUES (2, NULL)
INSERT datedemo (a, d) VALUES (3, '')
INSERT datedemo (a, d) VALUES (4, '12:24:34')
go
SELECT * FROM datedemo ORDER BY a
go
DROP TABLE datedemo
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||> I type in 01/01/1753 as the default value of the table designer
Without quotes, this is likely being interpreted as 1 divided by 1 divided
by 1753, which is going to round (dur to integer math) to 0, which is the
base date, 1900-01-01.
If you use a proper and unambiguous format for your date, you can avoid this
kind of thing. (And don't use the table designer.)
CREATE TABLE dbo.MyTable
(
i INT IDENTITY(1,1),
dt DATETIME NOT NULL DEFAULT '17530101'
);
GO
SET NOCOUNT ON;
INSERT dbo.MyTable DEFAULT VALUES;
INSERT dbo.MyTable(dt) SELECT '19000101';
INSERT dbo.MyTable(dt) SELECT '20050101';
INSERT dbo.MyTable(dt)
SELECT CONVERT(DATETIME, 01/01/1753);
GO
SELECT i,dt FROM dbo.MyTable ORDER BY i,dt;
GO
DROP TABLE dbo.MyTable;
GO|||The group is on a rampage for some odd reason.
Make sure you didn't accidentally define the data type as SMALLDATETIME,
which has a lower bound of '1900-01-01 00:00:00.000'.
Sincerely,
Anthony Thomas
"Mark_S" <Mark_S@.nospam.nospam> wrote in message
news:%23$GRC7$1FHA.2056@.TK2MSFTNGP10.phx.gbl...
> Hi
>
> I am using 01/01/1753 to define the "Empty Date" for my datetime fields.
>
> My tables have several columns that are defined as datetime fields which
> need to default to the empty date that I have chosen.
>
> I type in 01/01/1753 as the default value of the table designer, however
> when I insert a new line into any of the tables, the value that gets
> inserted is 01/01/1900.
>
> Does anyone know why this is happening? I am assuming that I have some
> configuration value set incorrectly.
>
> I realise that I could simply use 1900 as the empty date. I could also
> include the field and a value in the insert statement, but that isn't the
> point. I'd rather know why the system behaves like this.
>
> Hope someone can help
>
> Thanks in anticipation
>

Default value does not get written

I have a CreatedOn field , datetime, which has GetDate() as the default
value. When I create a new record in the table itself, the field gets
populated OK, but when I try to create a new record with a Microsoft
datagridview control, I notice that the datecreated value does not get
created. It looks as if the datagridview insert statements override the
default value and prevent the default defined in the table to get written.
Any ideas on how to overcome this? I<ve looked in the dataridview controls
properties and the dataset properties for this table and don't find anything
simple to let me ensure that on an insert my default value defined in the
table is the one saved.
It looks like I will have to do something in SQL server itself.
Any help would be appreciated.
BobThis is not an engine issue. I suggest you post this to an ADO.NET group whe
re such experts
hopefully has some suggestions. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bob" <bdufour@.sgiims.com> wrote in message news:e%23bHrSUmGHA.4268@.TK2MSFTNGP05.phx.gbl...

>I have a CreatedOn field , datetime, which has GetDate() as the default val
ue. When I create a new
>record in the table itself, the field gets populated OK, but when I try to
create a new record with
>a Microsoft datagridview control, I notice that the datecreated value does
not get created. It
>looks as if the datagridview insert statements override the default value a
nd prevent the default
>defined in the table to get written.
> Any ideas on how to overcome this? I<ve looked in the dataridview controls
properties and the
> dataset properties for this table and don't find anything simple to let me
ensure that on an
> insert my default value defined in the table is the one saved.
> It looks like I will have to do something in SQL server itself.
> Any help would be appreciated.
> Bob
>|||It would be easier for us to assist you if you were to provide the table
DDL.
I suspect that the application/dataadapter/ADO is taking the current value
of the datagrid cell (probably an zero or empty string) and using that in
the INSERT command.
Default values ONLY occur IF no value is INSERTed. If an empty string or
zero is INSERTed, then it is accepted.
If you are unable to control this behaviour in the application, you may have
to create a INSERT Trigger that changes the zero/empty strings into
getdate().
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"Bob" <bdufour@.sgiims.com> wrote in message
news:e%23bHrSUmGHA.4268@.TK2MSFTNGP05.phx.gbl...
>I have a CreatedOn field , datetime, which has GetDate() as the default
>value. When I create a new record in the table itself, the field gets
>populated OK, but when I try to create a new record with a Microsoft
>datagridview control, I notice that the datecreated value does not get
>created. It looks as if the datagridview insert statements override the
>default value and prevent the default defined in the table to get written.
> Any ideas on how to overcome this? I<ve looked in the dataridview controls
> properties and the dataset properties for this table and don't find
> anything simple to let me ensure that on an insert my default value
> defined in the table is the one saved.
> It looks like I will have to do something in SQL server itself.
> Any help would be appreciated.
> Bob
>

Friday, February 17, 2012

default value

how can i insert a default value for a datetime field, with something like the VB '=Now()' ?
thxINSERT table(column) VALUES(GETDATE())
INSERT table(column) VALUES(CURRENT_TIMESTAMP)
You could also set the column to have a default value, and leave it out of
your insert statement, e.g.
CREATE TABLE blat
(
foo INT NOT NULL PRIMARY KEY,
splunge DATETIME NOT NULL
DEFAULT GETDATE()
)
GO
INSERT blat(foo) VALUES(1)
WAITFOR DELAY '00:00:02'
INSERT blat(foo) VALUES(2)
SELECT foo, splunge FROM blat
GO
DROP TABLE blat
GO
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Phalle" <anonymous@.discussions.microsoft.com> wrote in message
news:340BC29F-9362-448D-B0A8-ED80BF8C67F1@.microsoft.com...
> how can i insert a default value for a datetime field, with something like
the VB '=Now()' ?
> thx

Default Value

Hi!
I have the following sp:
ALTER PROCEDURE dbo.[Buscar Clientes]
(
@.Begin As DateTime = Null,
@.End As DateTime = Null
)
In VS 2003, If i dont enter any value in the parameters, shouldnt both be
Null?
If i dont enter any value for the parameters i get the following error when
i use the Fill method: "String was not recognized as a valid datetime"
When i look into the Parameters in my DataAdpter, the value field is empty.
Can anyboy help me out?
Thanks,
BRuno N> In VS 2003, If i dont enter any value in the parameters, shouldnt both be
> Null?
YEs, they are NULL as far as T-SQL is concerned.

> If i dont enter any value for the parameters i get the following error
when
> i use the Fill method: "String was not recognized as a valid datetime"
I assume this stored procedure then returns a resultset, and this is what
you are using for Fill. Your C# or VB.Net code needs to deal with DBNull...
or, you need to change your SELECT statement so that IT deals with the NULL
values appropriately.
In other words, your error is not because your date is NULL within SQL
Server, your error is because your .NET code does not deal with it
correctly.|||Thank you!
I will look into my code
"Bruno N" <nylren@.hotmail.com> escreveu na mensagem
news:%23Z5g3pkLFHA.2604@.TK2MSFTNGP10.phx.gbl...
> Hi!
> I have the following sp:
> ALTER PROCEDURE dbo.[Buscar Clientes]
> (
> @.Begin As DateTime = Null,
> @.End As DateTime = Null
> )
> In VS 2003, If i dont enter any value in the parameters, shouldnt both be
> Null?
> If i dont enter any value for the parameters i get the following error
> when i use the Fill method: "String was not recognized as a valid
> datetime"
> When i look into the Parameters in my DataAdpter, the value field is
> empty.
>
> Can anyboy help me out?
> Thanks,
> BRuno N
>|||Bruno,
You can assign DBNull.Value to the parameter value. You can also not append
the parameters to the collection at all, ADO.NET use named parameters when
using sqlClient data provider.
AMB
"Bruno N" wrote:

> Thank you!
> I will look into my code
> "Bruno N" <nylren@.hotmail.com> escreveu na mensagem
> news:%23Z5g3pkLFHA.2604@.TK2MSFTNGP10.phx.gbl...
>
>

default value

how can i insert a default value for a datetime field, with something like t
he VB '=Now()' ?
thxINSERT table(column) VALUES(GETDATE())
INSERT table(column) VALUES(CURRENT_TIMESTAMP)
You could also set the column to have a default value, and leave it out of
your insert statement, e.g.
CREATE TABLE blat
(
foo INT NOT NULL PRIMARY KEY,
splunge DATETIME NOT NULL
DEFAULT GETDATE()
)
GO
INSERT blat(foo) VALUES(1)
WAITFOR DELAY '00:00:02'
INSERT blat(foo) VALUES(2)
SELECT foo, splunge FROM blat
GO
DROP TABLE blat
GO
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Phalle" <anonymous@.discussions.microsoft.com> wrote in message
news:340BC29F-9362-448D-B0A8-ED80BF8C67F1@.microsoft.com...
quote:

> how can i insert a default value for a datetime field, with something like

the VB '=Now()' ?
quote:

> thx