SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to combine and convert two integer columns to datetime


how to combine and convert two integer columns to datetime

Author
Message
Orlando Colamatteo
Orlando Colamatteo
SSC Guru
SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)

Group: General Forum Members
Points: 78492 Visits: 14499
ChrisM@Work (3/18/2013)
opc.three (3/15/2013)
PS Forgot to mention the function is undocumented so take that into consideration.

It's a cough scalar function too.

Meh. We're talking about SQL Agent data so IMHO it's not something to get in a twist over (or even having a cough over) :-D

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (167K reputation)SSC Guru (167K reputation)SSC Guru (167K reputation)SSC Guru (167K reputation)SSC Guru (167K reputation)SSC Guru (167K reputation)SSC Guru (167K reputation)SSC Guru (167K reputation)

Group: General Forum Members
Points: 167843 Visits: 39505
opc.three (3/18/2013)
ChrisM@Work (3/18/2013)
opc.three (3/15/2013)
PS Forgot to mention the function is undocumented so take that into consideration.

It's a cough scalar function too.

Meh. We're talking about SQL Agent data so IMHO it's not something to get in a twist over (or even having a cough over) :-D


Actually, the OP never did say if it was SQL Agent data that he was working with here. It could actually be data in his application database.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Orlando Colamatteo
Orlando Colamatteo
SSC Guru
SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)

Group: General Forum Members
Points: 78492 Visits: 14499
Lynn Pettis (3/18/2013)
opc.three (3/18/2013)
ChrisM@Work (3/18/2013)
opc.three (3/15/2013)
PS Forgot to mention the function is undocumented so take that into consideration.

It's a cough scalar function too.

Meh. We're talking about SQL Agent data so IMHO it's not something to get in a twist over (or even having a cough over) :-D


Actually, the OP never did say if it was SQL Agent data that he was working with here. It could actually be data in his application database.

Well, gee, I was thinking that was implied given the format of the data and was validated by the fact that the OP latched onto the msdb proc when replying directly to me, but you have a valid point. He could have been talking about data in an application database, or come to think of it, he could also have a shedload of historical data in his SQL Agent history tables but that would likely point to job-history maintenance issue.

@naveen.pasupuleti, could you tell us if you're applying this to SQL Agent data stored in msdb, or some other type of data source where you could be evaluating a non-trivial number of rows?

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Naveen PK
Naveen PK
SSC Eights!
SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)

Group: General Forum Members
Points: 926 Visits: 411
It is an application database used for reporting purposes, where I need to calculate datetime out of two integer columns (till last week, I calculated only date but new requirement asks for date and time). However, these int columns get data from msdb.dbo.sysjobservers as source table.
This function msdb.dbo.agent_datetime(@int1, @int2) is helpful for me in both ways:
1. I applied for my immediate reporting purposes
2. I added a datetime column in my table, updated column for current data and used this function in SSIS package.

All solutions are good but built-in function is new learning & quick for me.
I appreciate each of you for your responses.

Thanks,
Naveen.

Thanks,
Naveen.
Every thought is a cause and every condition an effect
Orlando Colamatteo
Orlando Colamatteo
SSC Guru
SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)

Group: General Forum Members
Points: 78492 Visits: 14499
OK, SQL Agent data, that's good, the use case fits, but you're repurposing it so how much data are we talking about? For managing SQL Agent historical data the scalar-function is fine because the volume is limited (if the instance is configured well) but if we're talking about a non-trivial amount of data you should consider switching to a home-made table-valued function instead. It will scale much better and not use anywhere near as much CPU.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Naveen PK
Naveen PK
SSC Eights!
SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)SSC Eights! (926 reputation)

Group: General Forum Members
Points: 926 Visits: 411
Weekly once ~800 records. It should ok to use function at the moment.
Yes, I would consider using TVF if data is significant.

Thanks,
Naveen.
Every thought is a cause and every condition an effect
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search