Showing posts with label sql2005. Show all posts
Showing posts with label sql2005. Show all posts

Monday, March 19, 2012

Date Insert

I'm a beginner to SQL Server 2005.

I'm building a small form with a SQL2005 database. I'm creating the database and adding a field called DateInsert. When the user clicks the submit button and the form data gets written to my database, how do I automatically generate a timestamp and write it to my DateInsert Field in the database?

Thanks in advance!

Hello,

You can use GetDate() in your insert statement. Such as:

INSERT INTO MyTableName

(ID,FIELD1,FIELD2,TIMESTAMP) VALUES (1,"Example","Example", GetDate())

Hope this helps.

|||

Thanks for your help. That is what I needed.

Is there a way to bind this to the FormView Insert Item on the formview control? I'm looking for the autogenerated code for the control and can't seem to find it.

|||

You can avoid the extra work and just take care of it on the database-end like described above.

|||

Or you can use the getdate() as the default value for that column. This can be done in enterprise manager.

|||

You can use default constraint with the field if you are sure you want the current date time value to appear in the field on every insert. Below is the syntax you can use at the time of creating a table.

create table <table name>( <column name>datetime default (getdate() ), )

If you've already created the table then below is the alter query you can use to set the default value constraint.

alter table <table name>add constraint [df_<table name>_name>]default (getdate() )forname>
 
 If you've added the default constraint for any column using one of above queries then you don't need to include that column in the insert list,
the default value will automatically inserted for that column.
The way is provide getdate() as the value for that field in the Insert query.
Hope this will help. 

Thursday, March 8, 2012

Date Formate in SQL2005 Reporting

Hi,

iam using a datepicker to pass the parameter "From Date" the datepicker date formate ismm/dd/yyyy but i want to change dis todd/mm/yyyyformate.

wat to change to get my requeriment.

Thxs in advance.

HI

Try this in c#

DateTime datetime = new DateTime();
datetime = DateTime.Parse(month.ToString());
string[] monthname = datetime.GetDateTimeFormats();
date= monthname[6].toString();

|||

Thxs karthikeyan for ur quick reply, but i asked for SSRS

|||

Use dd/MM/yyyy as the format in the Field. Make sure ds and ys are lowercase, Ms are uppercase.

|||

This should give you a good start in using custom expressions in SSRS. It may be C#, but it is still SSRS.

http://msdn2.microsoft.com/en-us/library/ms155798.aspx

|||

if your input parameters to the report go through a stored procedure, then you can check the dates and cobnvert them into any format or transpose them as necessary inside the sql server stored procedure using datepart() and datename() functions.

|||

actually i used the datepicker in the report.....iam displaying this parameter in the report like "Employess from this date to this" but the datepicker date formate is "MM/dd/YYYY"

i want to change this to "dd/mm/yyyy"...i have 2 write code in da report.

Thxs.