Skip to main content

Posts

Table Variable - Sql Server

Microsoft first time introduce Table variable in sqlserver 2000. it is alternative to using temporary table, but has some difference. Table variable acts like general table to  store, update, delete and delete records. Table variable store in TempDB in sqlserver. I will explain TempDB in later. Table variable declaration similar to CREATE TABLE Statement Declaration : DECLARE @MyProducts TABLE (        Id                 INT       , ProductName  VARCHAR ( 200 )       , Price              numeric ( 18 , 0 ) ) DML Operation: DML operation as it is general table operation. You can use tablevariables in batches, stored procedures, and user-defined functions (UDFs). We can UPDATE records in our table variable as well as DELETE records. ...

Efficiently Paging Through Large Amounts of Data (PageIndex, Page Size) -SQL Server

In this article you learn how to fetch data according PageIndex and PageSize. In web application, it is much more important to increase webform performance, loadbalance. In my development experience, some of table hold large amount of records (more than 2GB) and user need to shows records in GridView. But problem is when we select all records and loads in webforms, webform has crashed. In that case, I will simply solved with Table Variable and using Grid Page Number and Page Size. 1. Create Procedure CREATE PROCEDURE Load_Data_WithPaging @PageIndex AS INT , /*Selected Row Index of selected grid*/ @PageSize AS INT , /*Total page size of selected grid*/ @TotalRecords AS INT OUT /*used for display virtual page no*/ AS BEGIN SET NOCOUNT ON ; DECLARE @FromIndex AS INT = 0 , @ToIndex AS INT = 0 ; SET @FromIndex = (@PageIndex * @PageSize) + 1 ; /*First row no selection*/ SET @ToIndex = ((@PageIndex...

Password only alphanumeric no special character -MVC C#

Password matching expression. Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit. Expression:   ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$ public class LoginViewModel { [ Required (ErrorMessage= "Required" )]       [ Display (Name = "User name" )] public string UserName { get ; set ; } [ Required (ErrorMessage = "Required" )] [ DataType ( DataType .Password)] [ RegularExpression ( "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$" , ErrorMessage = "Password Alphanumeric Only. Minimum length 8" )] [ Display (Name = "Password" )] public string Password { get ; set ; } }

Remove the last character in a string in -C#

You can remove last character or no of last character with below code. please try this.   static void Main( string [] arg)         {                  string temp = "My Name is Mohammad Maksudur Rahman.>" ;        var stringValue = temp.Remove(temp.Length-1);                   Console .WriteLine( "Your string value: {0}" , stringValue);                 Console .ReadLine();           stringValue = temp.Remove(temp.Length-2);           Console .WriteLine( "Your string value: {0}" , stringValue);                 C...

Get Previous Month's First and Last Date -C#

Here this code, your can get previous month's first and last day. It's simple   static void Main( string [] arg) {    var year = DateTime .Today.Year;    var month = DateTime .Today.Month;    var firstDate = new DateTime (year, month, 1).AddMonths(-1);    var lastDate = new DateTime (year, month, 1).AddDays(-1);    Console .WriteLine( "First day Previous Month: {0}" , firstDate);    Console .WriteLine( "Last day Previous Month: {0}" , lastDate);    var  lastday =  GetMonthLastDate ( 2015 , 6 );   Console .WriteLine( "Last day : {0}" , lastDate);    Console .ReadLine(); } You can use below method to get last date of any month of the any year. private DateTime GetMonthLastDate( int year, int month) {     return new DateTime (year, month, DateTime .DaysInMonth(year, month)); }

Remove the last character in a string in -SQL Server

Remove last character  or no of character remove in SQL server. Its so easy in sqlserver built in function with SUBSTRING , sometimes its little bit tricky for developer when he/she forget about SUBSTRING method. SUBSTRING ( expression ,start , length ) Original String is  'My Name Is Maksud,' SELECT SUBSTRING('My Name Is Maksud,', 1, LEN('My Name Is Maksud,') - 1) AS ResultString You can do this in C#, here you go  Remove the last character in a string in -C#

ROW_NUMBER -Sqlserver

This is a special keyword used for generate "Sequential No'   on a row within result set. Sequential no start from 1 for first row, second row no is 2 in each partition. Usually used in Select Statement. ROW_NUMBER () OVER ( [ <partition_by_clause> ] <order_by_clause> )  Arguments: ROW_NUMBER has Two Arguments are  1. Partition_by_clause and 2.   order_by_clause  ROW_NUMBER() with PARTITION : Partition BY Clause to generate Sequence No to separate of query result and Order By works on over clause for order the results. SELECT  ROW_NUMBER() OVER(PARTITION BY IsApproved ORDER BY Id DESC ) AS SL_NO ,[Name]       ,[Address]       ,[Telephone]  ,[IsApproved]       FROM [RemitERP].[dbo].[Agm_Agent]  WHERE IsApproved IS NOT NULL ROW_NUMBER()   Only  ORDER BY : Order by clause works all result of the query and generate sequence No.  SELE...