glo-dba
asked on
TSQL question: How can I perform a calculation on on multiple values?
Hello Experts,
I need to return values like this '131531013' into a date format like 2007/1/5. I have the math for it:
declare @tsdate int
set @tsdate = 131531013
declare @day int
declare @month int
declare @year int
select @day = @tsdate % 256
select @month = (@tsdate % 65536) / 256
select @year = @tsdate / 65536
but I'm stuck on getting it into a multi-row dataset.
Thanks!
Keith
I need to return values like this '131531013' into a date format like 2007/1/5. I have the math for it:
declare @tsdate int
set @tsdate = 131531013
declare @day int
declare @month int
declare @year int
select @day = @tsdate % 256
select @month = (@tsdate % 65536) / 256
select @year = @tsdate / 65536
but I'm stuck on getting it into a multi-row dataset.
Thanks!
Keith
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> but I'm stuck on getting it into a multi-row dataset
If you mean run that logic on a column of values, yes ... you could put the logic into a UDF. Then call the UDF from your query. Example in MS SQL:
SELECT dbo.ConvertIntToDate( SomeIntegerCol ) FROM TheTable ....
http://msdn.microsoft.com/en-us/library/ms186755.aspx
http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html
Also, is your int value ("131531013") some sort of epoch? Just wondering if there's an easier way to do the conversion.