Showing posts with label Questions & Answers. Show all posts
Showing posts with label Questions & Answers. Show all posts

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.



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, 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

Monday, 31 March 2014

Find Length of string with LEN function in sql server

It returns the number of characters of string expression but with excluding trailing blanks.

SELECT LEN('Sql Server Database')

-- Result : 19


Tuesday, 25 March 2014

Find Age from Date of Birth in Sql Server


declare @dob datetime = '1952-08-14 21:11:19.300'

select CAST( DATEDIFF(Y , @dob , getdate() )/365.25 as int)

-- 365 are the Number of Average days in 4 years


Sunday, 23 March 2014

Select Top N rows from a table in Sql Server

Suppose if N=10 then ,

Select Top 10 * from Person

IF you want to Select only particular columns then,

Select Top 10 Name , City , Age from Person




Get current system date in Sql Server

SELECT GETDATE()

-- Result : 2014-03-23 19:57:21.630


Wednesday, 12 March 2014

Find Version of Sql Server through query

select @@Version

Result from My Computer:

--Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
--Feb 10 2012 19:39:15
--Copyright (c) Microsoft Corporation
--Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )


Wednesday, 5 March 2014

#region in Visual Studio

It allows block of code to expand or collapse when using the outlining feature of the Visual Studio Code Editor. You can write namespaces, classes, methods, interfaces, delegates, events inside it.

#region MyRegion

//  Namespaces
//  Classes
//  Methods
//  Interfaces
//  Delegates
//  Events

#endregion