ivonko.com

Archive for December, 2009

Oracle Timestamp Difference in seconds

by on Dec.23, 2009, under Development

select (TO_NUMBER(TO_CHAR(EndDate,’J'))-TO_NUMBER(TO_CHAR(CreateDate,’J')))*86400 + (TO_NUMBER(TO_CHAR(EndDate,’SSSSS’))-TO_NUMBER(TO_CHAR(CreateDate,’SSSSS’))) AS “Delta (sec)” from table1

Comments Off more...

MSSQL function charindex-at-n-position

by on Dec.17, 2009, under Development

To find the charindex of an expression “_” in n position say 3rd occurancein a given word ‘xx_xxx_xx_xx’
Result : 10
SELECT dbo.fn_charIndex(‘_’,3,’ xx_xxx_xx_xx’)

—————————————————————

And the code for creating function:

Create  function dbo.fn_charIndex(@Expression varchar(256),@nPos int,@Word varchar(2000))
returns int
as
begin
declare @ret int,@strt int
set @ret = 0
set @strt = 0
while not @strt = @npos
begin
select @ret = charindex(@Expression,@Word,@ret+1)
set @strt = @strt +1
end
return @ret
end

—————————————————————

Source: http://www.calsql.com/2009/10/function-charindex-at-n-position.html

Comments Off :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...