Wednesday, 16 October 2019

Publish your project in visual studio

You need to click on the Build menu and then select Publish ,



Once the Dialog has been open you need to specify the publishing target , Since we choose the file system so we need to click on "Folder", Then we gonna need to specify the target location for that
but visual studio will choose a default location as well after getting done with that you just simply need to click on "Publish" button and It's done! Now you can pick the published code from your chosen target location and can deploy it as you want.



Tuesday, 15 October 2019

Adding jQueryUI library in MVC Project

First you need to download JqueryUI via their website or Nuget Package manager, Once you get it in your project you need to add it into BundleConfig.cs file like below:

    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {

            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
            "~/Scripts/jquery-ui-{version}.js"));
        }
    }

Now you can add it in your _Layout page :

   @Scripts.Render("~/bundles/jqueryui")         



Monday, 24 September 2018

AVG() function in sql server


It will return the average value of a numeric column .

Syntax:
SELECT AVG(column_name)
FROM table_name

Example:
SELECT AVG(totalMarks)
FROM Students

Tuesday, 3 January 2017

IIF function in SQL Server

It is a SQL Server function in which you specify an expression and two possible result values,
So if the condition satisfies then it returns the first value if not then it returns the second.
You can also use it instead of CASE , in fact it is a shorthand for CASE . The query execution
plan Is also the same it just increase the readability so you might call it as  Syntactic sugar
for your code. It is familiar to ? keyword  used in c# .

Syntax:

IIF ( Boolean_expression, True_value, False_value )  


Examples:

SELECT IIF( 33 > 3,  'true' , 'false')

-- Result :  true


SELECT IIF( 2 > 3,  'true' , 'false')


-- Result :  false 


DECLARE  @passingMarks INT = 33 , @achievedMarks INT = 70
SELECT IIF(@achievedMarks >= @ passingMarks ,  'Congratulations! You have passed'  ,  'Sorry! You ditn’t make it')


-- Result :  Congratulations! You have passed




Tuesday, 27 September 2016

How to get definition of Stored Procedure in Sql Server


If you have a stored procedure name "GetStudents" and you want to get it's defintion then
you need to write:

sp_helptext  'GetStudents' 

so syntax is : sp_helptext <your stored procedure name>


Monday, 19 October 2015

Paging of Large Datasets in Sql Server

When you are fetching large "datasets" using ROW_NUMBER(), you might experience a long
delays in getting result and sometime it timeout expired, To overcome this situation you 
need a better and efficient approach, Fortunately there is an efficient solution for that
teasy situation but question is what .

"Table Variables" are light weight because they does not allow explicit addition of indexes 
after it's declaration only implicit indexes can be created using primary key or unique key 
and also scope of the table variable is the Batch or Stored Procedure in which it is declared. 
And they can’t be dropped explicitly, they are dropped automatically when batch execution completes or the Stored Procedure execution completes. 

So in a situation like this it can be useful in a way that create a table variable and insert
fetched data in it along with an auto incremented id then fetch the records from that
temp table with paging filter applied then you would get you expected result.


Here is a small demonstration :

CREATE PROCEDURE GetEmployee
       @PageSize BIGINT = 10,
       @PageNo BIGINT = 1
AS
BEGIN
       SET QUOTED_IDENTIFIER OFF

       DECLARE @TempItems TABLE (
               Rowid BIGINT IDENTITY
              ,EmployeeID BIGINT
              ,EmployeeName VARCHAR(155)
              )

       DECLARE @maxRow BIGINT    
       SET @maxRow = (@PageNo * @PageSize) + @PageSize + 1
       SET ROWCOUNT @maxRow

       INSERT INTO @TempItems (
               EmployeeID
              ,EmployeeName
              )
       SELECT *
       FROM Employee

       SET ROWCOUNT @PageSize

       DECLARE @minimumRange BIGINT, @maximumRange BIGINT

       SET @minimumRange = (@PageNo * @PageSize) - @PageSize
       SET @maximumRange = (@PageNo * @PageSize + 1)

       SELECT *
       FROM @TempItems t
       WHERE Rowid BETWEEN @minimumRange AND @maximumRange

       SET ROWCOUNT 0

END