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

Thursday, March 22, 2012

Conert Char to Datetime

Hello,

I have made a slight error in my SQL2000 database and have found this out with 10000 plus records under my belt.

I have a field called Char with entries 12mid and 12noon. I need to convert these to Datetime. All records convert OK except these two.

I am using DTS to transfer records form old table to new table. How do I write a procedure (or something) to enable conversion of the records 12mid and 12noon to 12am and 12pm.

Thanks

GoongYou run one batch that "REPLACE"s noon/mid with pm|||pkr,

When you say batch, what exactly is that. Is is the transformation in the DTS options.
When you say replace, how would I go about it, Is it through a query, if so, how would it possibly look.

Thanks
Goong|||Batch as in 'SQL Query'. You can run a batch in DTS but since you prob' want to do this once I'd just run it from your fav' query tool.

The clue was in my response, "REPLACE". Use it with an Update query.

Monday, March 19, 2012

Conditional statement with a cast from string to date

My source file is showing column 10 as string. My destination table is datetime. I am using the derived transformation with a conditional statement. How do I convert the value from string to date. Everywhere I try the (DT_DATE) I get an error.

[Column 10] == "01/01/0001" ? " 01/01/1801" : [Column 10] <= "12/31/1801" ? "12/31/1801" : [Column 10]

What's the error?|||

I modified it to the following but I get an error when I try to debug.

[Column 10] == "01/01/0001" ? (dt_date)" 01/01/1801" : [Column 10] <= "12/31/1801" ? (dt_date)"12/31/1801" : (dt_date)[Column 10]

Error message is:

...conversion between types dt_str and db_timestamp is not supported

|||What is the output column data type specified as in the derived column?|||Where do I check that? I only see the input defined in the derived column transformation which is dt_string 50. The column is defined as datetime in the table.|||http://ssistalk.blogspot.com/2007/01/derived-column.html

I would expect to see the data type of the derived column be DT_DBTIMESTAMP (or DT_DBDATE). The expression should be:

[column10] == "xxxxxx" ? "01/01/1801" : ......

Make sure "Derived Column" is set to "add as new column".|||I don't want to add it as a new column. I am using the conditional statement instead of the SQL case statement. I have dates from Oracle that are outside SQL's range that I need to convert.|||Right, but you can't replace the column because it's a DT_STR.... So if you want a date data type, you need to have a new column. This is the proper way to do it. Then in the data flow, you just ignore [column10] and use [DateColumn10], for instance.|||I tried that but now I get the same error for my new column10.|||

RMooreFL wrote:

I tried that but now I get the same error for my new column10.

Okay, I've posted a new example.

http://ssistalk.blogspot.com/2007/01/derived-column.html

Sunday, March 11, 2012

Conditional Split - DatTime Condition

Hi,

How do I make a condition for a DateTime field?

The SQL that I use for it is:

select..

from..

where...anddatePart(hh, myDateTimefield)> 10

Thank you!! Smile

If you look in BOL for Expressions in SSIS you'll see it is much the same.|||BOL?|||BOL = Books on Line. SQL's help file.

For a Conditional split, in the condition you would put your condition. Example: Col1 == 1

This would cause any column with a value of 1 to go to that output. Anything not matching any one of the conditions would go to the default output.

Options are:
== (Double =)
<=
>=
!=

See BOL for Conditional Split help.

Conditional Split - DateTime Condition

Hi,

I'm trying to check if a row was created yesterday?

This does not seem to work?

(MyId == "10") && DATEPART("dd",GETDATE()) == (DATEPART("dd",MyDateTimeColumn) - 1)

Does anybody know how I can accomplish this?

Many thanks.

Two things...

First, you should surround your DATEPART equality checks in parenthesis.

(MyID == "10") && ( datepart stuff here )

Second, you probably shouldn't subtract one from the result of datepart("dd",MyDateTimeColumn), instead, you should use datepart("dd",dateadd("dd",-1,MyDateColumn))|||

Hi Mr. Hat,

I would try something similar to

(MyId == "10") && MyDateTimeColumn == DATEADD("dd", -1, GetDate())

Hope this helps,

Andy

|||

Andy Leonard wrote:

Hi Mr. Hat,

I would try something similar to

(MyId == "10") && MyDateTimeColumn == DATEADD("dd", -1, GetDate())

Hope this helps,

Andy

HAHAHAHA! (Sorry, but I blindly overlooked the part where the user was comparing day of months.) Yeah, do what Andy suggests. There's no need to compare "days" to each other. Just compare the dates. However, cast them to dt_dbdate first, to eliminate time.

(MyId == "10) && ((DT_DBDATE)[MyDateColumn] == (DT_DBDATE)DATEADD("dd",-1",GetDate()))|||

Brilliant! It worked.

Thank you so much!!

Conditional Split - Compare DATETIME with constant

Hi,

I have to compare a DATETIME Field with '1/1/1900 12:00:00 AM". Which is default DATE TIME Value in SQL Server.

I did compare like

TRADEAGREEMENTFROMDATE != (DT_DBTIMESTAMP)(DATEPART("mm",(DT_DBTIMESTAMP)"1/1/1900 12:00:00 AM"))

but (DT_DBTIMESTAMP)(DATEPART("mm",(DT_DBTIMESTAMP)"1/1/1900 12:00:00 AM")) returns "12/31/1800 12:00:00:AM"

Thanks,

Aravind

So the value I got was slightly different.

(DT_DBTIMESTAMP)(DATEPART("mm",(DT_DBTIMESTAMP)"1/1/1900 12:00:00 AM")) = 31/12/1899 00:00:00

Why are you using DATEPART? Do you not just want -

(DT_DBTIMESTAMP)"1/1/1900" = 01/01/1900 00:00:00

That is the same as '1/1/1900 12:00:00 AM' which you asked for above, infact the time format is just my local settings UK rather than US, the values are exactly the same.

Wednesday, March 7, 2012

Conditional Formatting on Datetime Field

I am building a report with a query that includes a field of type datetime.
I would like to change the color of the text in this column to RED if the
value contained in the field is earlier than now() - 10 minutes. I would
appreciate direction as to the appropriate function to use in this scenario.
I have tried to work with datediff, but without positive results.
Regards,
Pete Zerger, MCSE(Messaging)
Co-founder and Webmaster, MOMReourcs.org
URL:http://www.momresources.org
mailto:pete.zerger@.gmail.comWill something like this work for you?
=iif(Fields!EventDate.Value < dateadd("n", -10, Now()), "Red", "Black")
Regards,
Dan

Tuesday, February 14, 2012

concurrency and timestamp or datetime

Hi everyone!

I've read a lot of document about optimistic concurrency and different implementations which made me decide to chose the timestamp/datetime approuch to validate if another user has editet the record.

I'm saying timestamp OR datetime because I dont really care which one to use but I can't make any of them work as expected.

Here is my setup:

I'm using a DataSet (autogenerated by Visual Studio 2005) with 4 stored procedures to select, update, delete and insert records.
I'm using a GridView to show these values but when using a timestamp in the database the parameter type in my ObjectDataSource is an Object which ofcause ins't right and I can't change it to Byte[].
If I instead use a Datetime I believe that the date formatting is done somehow (even though i make the field ReadOnly in the GridView) - I can see the date is shown as:"01-01-1900 00:01:07" but the actually SQL that is executed is: 'Jan 1 1900 12:01:07:000AM' why this differense?

So my question is which one should I use and how - the datetime/timestamp dosn't have to be shown - I would actually prefer that the datetime/timestamp was somehow hidden from the presentationlayer and only present in the data access layer but still would be transfered to and from the database when doing updates etc.

Best of all I could use a working example.

Thanks in advance :-)

There is a big difference between DateTime and Timestamp, the former is a data type while the late is a derived data type SQL Server uses internally for housing keeping. So Timestamp will not move with your data. Try the link below for a tutorial on concurrency. Hope this helps.

http://www.15seconds.com/issue/030604.htm

|||

Thanks for you reply.

I know there is a big difference between the two datatypes but that is not my problem - my problem is HOW to use one of them.

You are wrong about that "timestamp vil not move with your data" - what I've done to overcome my Byte[] problem is to cast the timestamp to char(8) - when I later want to make an update I compare with the timestamp (which is casted back from char(8) to timestamp). This works like it should but I just don't like this casting thing - there must be a better way.

I've allready read the artickel you've linked - among a lot of others. This one is unfortunally in VB which is not my strong side. Is there another one in C# that you know of?