Thursday, May 30, 2013

How to Get Numeric Values from String in SQL-SERVER

we can create udf and use it any where in our command

CREATE
FUNCTION dbo.GetNumeric_Report


(@strAlphaNumeric VARCHAR(4000))

RETURNS INT
AS
BEGIN
DECLARE @intAlpha INT
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
BEGIN
WHILE @intAlpha > 0
BEGIN
SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
END
END
RETURN CONVERT(INT, ISNULL(@strAlphaNumeric,0))
END

Explanation of Above code :

Major use of PATINDEX which takes first argument as patter and return the index of first accurance of match value from expression.
                                                           PATINDEX ( '%pattern%' , expression )
And then STUFF delete the accurance match index from expression.

this way only integer value saved.
TEST:
select dbo.GetNumeric_Report('ahgf254bshgw3548bjdgahgfkjla');

Saturday, May 4, 2013

How to know horizontal or vertical scroll bar is present or not in browser

This is work for all Browsers IE9, Chrome,Mozial, Windows Safari..

function IsScrollBarPresents() {
            window.scrollTo(1, 1);
           if (window.pageYOffset != 0) {
                alert("vertical scrollbar present");
            }
            if (window.pageXOffset != 0) {
                alert("horizontal scrollbar present");
            }
            window.scrollTo(0, 0);
        }

Thanks
Mahesh

How to know the table name dependence on its column name

select
column_name,table_name,* from information_schema.columns

where column_name like '%isf%'