Wednesday, 21 February 2018

How to create Roman Numerals function in SQL

Description : In this post how to generate roman numerals return function in sql

CREATE Function [dbo].[GetRomanNo] ( @N as varchar(20) )
RETURNS VARCHAR(100)
AS
BEGIN
  DECLARE @s varchar(100), @r varchar(100), @i bigint, @p int, @d bigint
  SET @s = ''
  SET @r = 'IVXLCDM' -- Roman Symbols

  /* There is no roman symbol for 0, but I don't want to return an empty string */
 IF @n=0
  SET @s = '0'
 ELSE
 BEGIN
  SELECT @p = 1, @i = ABS(@n)
  WHILE(@p<=5)
  BEGIN
   SET @d = @i % 10
   SET @i = @i / 10
   SELECT @s = (CASE WHEN @d IN (0,1,2,3) THEN Replicate(SubString(@r,@p,1),@d) + @s
        WHEN @d IN (4) THEN SubString(@r,@p,2) + @s
        WHEN @d IN (5,6,7,8) THEN SubString(@r,@p+1,1) + Replicate(SubString(@r,@p,1),@d-5) + @s
        WHEN @d IN (9) THEN SubString(@r,@p,1) + SubString(@r,@p+2,1) + @s END)
   SET @p = @p + 2
  END

  SET @s = Replicate('M',@i) + @s

  IF @n < 0
   SET @s = '-' + @s
  END

 RETURN @s
END

How to use if / else condition in sql server

Description : in this post display color code name when pass int value in @ColorCode variable if pass 2 in @ColorCode = 2 then it check condition and result will return "GREEN" bacause color code = 2 is green

DECLARE @ColorCode Int

SET @ColorCode = 2

IF (@ColorCode = 1)
BEGIN
 SELECT 'RED' AS ColorName
END
IF (@ColorCode = 2)
BEGIN
 SELECT 'GREEN' AS ColorName
END
IF (@ColorCode = 3)
BEGIN
 SELECT 'BLUE' AS ColorName
END

SQL DataType length

Description : in this post sql datatype store value in database and c# side

1. BigInt
    From C# side it stores Int64 Value
    MaxValue = 9223372036854775807
    MinValue = -9223372036854775808

2. Bit
    C# : Store Bool Value Like True or False

3. DateTime
    C# : Store Date Time

4. Float
    C# : Store Float Value
    MaxValue = 3.40282e+038f
    MinValue = -3.40282e+038f

5. Int
    C# : Store Int32 Value
    MaxValue = 2147483647
    MinValue = -2147483648

6. Numeric(18,0)
    SQL store value like 18 digits with 2 or more decimal place
    e.g. 12.00

7. Nvarchar(50)
    SQL store Text & unique code value with limited size

8. Nvarchar(MAX)
    SQL store Text & unique code value no limit for store data

9. Varchar(50)
    SQL store only text Varchar datatype do not support unique code value

10. Varchar(MAX)
    SQL store only text Varchar datatype do not support unique code value

11. Uniqueidentifier
    SQL store Numeric, Characters, and - with the lenth of 36 characters
    Uniqueidentifier do not repeat it generate unique value every time
    C# : store GUID value

Using a temporary table in dynamic sql query in a stored procedure

Description : in this post how to use temporary table in dynamic sql query first add city table data in #tmpCity and use in dynamic sql insert query

Declare @Sql Nvarchar(max),@Sql1 Nvarchar(max)

CREATE TABLE #tmpCity (CityIDP BigInt, CityName Varchar(50))

SET @Sql = 'INSERT INTO #tmpCity SELECT CityIDP, CityName  FROM mCity'
EXEC(@Sql)
SELECT @@ROWCOUNT
SET @Sql1 = 'SELECT * FROM #tmpCity'
EXEC(@Sql1)
GO
DROP TABLE #tmpCity

Introduction of ASP

ASP is a framework for develop web pages

Development tools for ASP

- Classic ASP

- ASP.NET Web Forms

- ASP.NET MVC

- ASP.NET Web Pages

- ASP.NET API

- ASP.NET Core

Description about ASP

- Classic ASP introduce in 1998 as first script langualge of Microsoft. classic asp file extension is .asp written in VB

Description about ASP.NET

- ASP.NET released in 2002 and file extension of ASP.NET is aspx written in C# and ASP.NET 4.7 is latest version of ASP.NET

Description about ASP.NET Web Pages

- ASP.NET Web Pages is and single page application similar to PHP and ASP.NET Web Pages mearged in ASP.NET Core

Description about ASP.NET MVC

- ASP.NET MVC s Model - View - Controller and this is also mearge in ASP.NET Core

Description about ASP.NET API

- ASP.NET API is Application Programming Interface and this is also mearge in ASP.NET Core

Description about ASP.NET Web Forms

- ASP.NET Web Forms is event driven application model and this is not a part of ASP.NET Core

Description about ASP.NET Core

- ASP.NET core release in 2016 and Core mearge ASP.NET, MVC, Web API and ASP.NET Web Pages