Tuesday, November 14, 2017

YAHOO Finance SymbolSuggest

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/cupertino/jquery-ui.css"></script>
    <script type="text/javascript">

        $(document).ready(function () {

        $("#stock").autocomplete({
            source: function (request, response) {

                // faking the presence of the YAHOO library bc the callback will only work with
                // "callback=YAHOO.Finance.SymbolSuggest.ssCallback"
                var YAHOO = window.YAHOO = { Finance: { SymbolSuggest: {} } };

                YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
                    var mapped = $.map(data.ResultSet.Result, function (e, i) {
                        return {
                            label: e.symbol + ' (' + e.name + ')',
                            value: e.symbol
                        };
                    });
                    response(mapped);
                };

                var url = [
                    "http://d.yimg.com/autoc.finance.yahoo.com/autoc?",
                    "query=" + request.term,
                    "&callback=YAHOO.Finance.SymbolSuggest.ssCallback"];

                $.getScript(url.join(""));
            },
            minLength: 2
        });
        });
    </script>
<meta charset="utf-8" />
</head>
<body>
    Stock Symbol
    <input id="stock" type="text" placeholder="type to search stocks" />
</body>
</html>

Thursday, September 28, 2017

Get top X from each category SQL SERVER 2005 +



Get top 5 from each category

simple logic use Row_Number function with partition by the category for which you want to create group.
 ROW_NUMBER() OVER (PARTITION BY CategoryID order by CategoryID  )

Step 2: Now Row_Number will add numbers on each category, kept the result in temp table or CTE.

Step 3: Now use select statement to get records where rowNum greater than X.


;with Rohi  as
(
 select
 TestID,CategoryID,
 ROW_NUMBER() OVER (PARTITION BY CategoryID order by CategoryID  ) AS  'RowNum'

  from Test
  )
  select * from Rohi where RowNum <=5