Informatica powercenter - sql-server

I have a flat file as source which contains two columns named "Event begin time" and "event end time" that has both date and time in it .
How can I calculate MOU(minutes of usage) for it using
Informatica.
Please help me..
Thanks
Vinay

The DATE_DIFF function can be used for calculating the time duration:
DATE_DIFF( Event_End_Time, Event_Begin_Time, MI)

First you need Informatica to know that each of the 2 dates from the flat file are indeed dates and the format from the INCOMING date fields, you will do this by passing them to an expression transformaton i.e. if they are in 'DD/MM/YYYY HH24:MI:SS' then the expression to turn them into date/time in informatica will be TO_DATE (EVENT_BEGIN_TIME, 'DD/MM/YYYY HH24:MI:SS') (You'll have to do same for event end time... I've used name with underscores instead of spaces as informatica doesnt allow spaces in port names)
Then you'll use datediff to subtract the begin time from the end time... lets say you named the 2 variable ports which contain the above calculation as v_BEGIN and v_END, the calculation for minutes will be DATE_DIFF(v_BEGIN, v_END, 'MI')

Simplest way of achieving it :
Consider T1 and T2 as Start time and end time (Ensure that,both are in DATE Format).
In variable calculate T2-T1 : This will give you difference in days.
Multiply it by ( 24*60 ) will give you number of minutes.
So, 24*60*(T2-T1).

Related

change the date in ssis package for XML file

I am working on SSIS in my XML file I have reading dates like 2013-08-02, 2013-08-4, 2013-08-05 but I have to change the data date to from last two days, What I mean is that the data date stamp should be changed to 2017-05-21,2017-05-22,2017-05-22.
what I was done is added a derived column in the SSIS package and changed the expression with GETDATE() in this case I am getting only today date, But I need to change data from last two days.
Can anyone help me?
Use the DATEADD function to add or subtract time from a date. In your Derived Column, use this in the Expression field:
DATEADD("d", -2, GETDATE())
Note that this does subtract the time value as well so if you need to convert to strictly date format (or time zone conversions) you will need additional code.

Adding Time Intervals SQL

I need to add time entries from a table. The time entries are stored as
P2H30M (2 Hours 30 Minutes)
What would be the best way to go about this?
Are you adding time intervals to other time intervals? Or time intervals to another column that's defined as a datetime?
Either way, you'd want to create a function to convert those values to an integer (minutes) and then add the integers together and use another function to convert them back to your proprietary character format.
If you're wanting to add them to a datetime column you could then use:
UPDATE YourTable
SET YourDateTimeCol = DATEADD(MI, YourDateTimeCol, <yourminuteinteger>)
WHERE <whatever your where clause would be>

How to make search on Time in sql server?

I have two columns in table Start time and end time. I want to make search on the basis of time. I have saved the start time and end time in below format
14:57:44
using Convert(varchar(20),Getdate(),108)
Please help me.
select * from your_table
where cast(time_column as time) between '10:00:00' and '11:00:00'

How to display time in HH:MM format?

How to display a time HH:MM format?
Using SQL 2000
In my Database time column datatype is varchar
Example
Table1
Time
08:00:00
09:00:23
214:23:32
Here I want to take only 08:00, 09:00, 214:23
How to make a query for this condition?
Whilst you could choose to turn the varchar into a datetime and format it there, assuming you do not want rounding, you could could shortcut the process. (Assuming the time format in the varchar is consistent)
select left('08:00:00',5)
Edit : Question altered, now I would use
select substring('243:00:00', 1, len('243:00:00') - 3)
and replace the value I used with the appropriate field
Cheap and cheerful.
I think Andrew was onto a correct solution, just didn't address all of the possibilities:
SELECT LEFT(Time, LEN(TIME)-3)
should trim off the last 3 characters.
Now, if you want to round up, that's another story....

SqlDateTime overflow Exception

I am trying to insert a time only value, but get the following error
ex {"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."} System.Exception
From the front end, the time is selected using the "TimeEdit" control, with the up and down arrows. The table in SQL Server has the fields set as smalldatetime. I only need to store the time. I use the following to return data to the app
select id,CONVERT(CHAR(5),timeFrom,8)as timeFrom,CONVERT(CHAR(5),timeTo,8)as timeTo
FROM dbo.Availability
where id = #id
and dayName = #weekday
How do I pass time only to the table?
Edit ~ Solution
As per Euardo and Chris, my solution was to pass a datetime string instead of a time only string. I formatted my result as per Time Format using "g".
Thanks
You can set the date to 1/1/1753 wich is date min value for datetime in MSSQL and then add the hour you want to store. Of course you have to consider this every time you need to get the value, but you can wrap that with some helpers.
Or you can use MSSQL 2008 and use the new TIME datatype.
Pick a date that is in the range(ie, 1/1/1970) and use it for everything you insert.
If you are only keeping track of the time, think about storing it in an int as an offset from midnight in whatever granualarity you need (seconds, minutes, hours, ...). You can then convert it to a TimeSpan in your code using the appropriate TimeSpan.From??() method. To go back the other way, you can use TimeSpan.Total?? and truncate if need be. If you need to do manual queries you can write a SQL function that will convert hours/mins/seconds to the equivalent offset.
I prefer this over using a datetime and picking an arbitrary day as it makes the purpose of the field clearer, which reduces confusion.
there is no such thing as Time in SQL, there is only DateTime.
For your purpose, I would use something like this to only return the time portion.
SELECT (GETDATE() - (CAST(FLOOR(CAST(GETDATE() as FLOAT)) AS DateTime)))
where GETDATE() is the datetime you want to filter.
When setting the time in the database, you will have to add '01/01/1901' or '01/01/1753' to the time.
Dont use CAST and Convert to varchar when working with datetime, its slow. Stick to floating numerical operations.

Resources