Skip to main content

Posts

Showing posts from July, 2016

How to get JSON or XML using SQL Server 2016 or Azure SQL Database

Here I will explain how to get JSON from SQL Server 2016 and Azure SQL Database. In SQL Server 2016 we will get JSON easily using "FOR json AUTO;" after the select statment. Here I will create one temp table for save data. CREATE TABLE #tmp( [FCAT_1] [varchar](500) NULL, [FCAT_2] [varchar](500) NULL )   INSERT INTO #tmp( FCAT_1, FCAT_2 )VALUES ( 'Apple','Banana') INSERT INTO #tmp( FCAT_1, FCAT_2 )VALUES ( 'Bike','Car') This query return JSON. SELECT * FROM #tmp FOR json AUTO;   Output : [{"FCAT_1":"Apple","FCAT_2":"Banana"},{"FCAT_1":"Bike","FCAT_2":"Car"}] This query return json with ROOT Name. Select * from #tmp For JSON PATH, ROOT('Result')   Output : {"Result":[{"FCAT_1":"Apple","FCAT_2":"Banana"},{"FCAT_1":"Bike","FCAT_2":"Car"}]} This q

URL Rewriting Using global.asax File In ASP.NET (C#)

Here I will explain URL rewriting using global.asax file. URL is useful for hide query strings from URL, change the page name or URL. Add one aspx page in your project and give name Login.aspx. Then after add this namespace on your global.asax file, using System.Web.Routing; Add this code in your global.asax file. protected void Application_Start(object sender, EventArgs e)    {       RegisterRoutes(RouteTable.Routes);   }   public static void RegisterRoutes (RouteCollection routecollection) {       routecollection.MapPageRoute("Login", "Login", "~/Login.aspx");   }   Run the Login.aspx page without page extension as " Login ". For ex:  http://localhost:51965/Login.aspx //before URL rewriting http://localhost:51965/Login //after URL rewriting

Get Month Name And Number In SQL SERVER

In this code snippet you will learn how to get monthname and number using SQL SERVER. SELECT number, DATENAME(MONTH, CAST(year(getdate()) as varchar(4)) +'-' + CAST(number as varchar(2)) + '-1') monthname FROM master..spt_values WHERE Type = 'P' and number between 1 and 12 ORDER BY Number OUTPUT : Number   monthname 1              January 2              February 3                   March 4              April 5                   May 6              June 7              July 8              August 9              September 10             October 11                 November 12             December