Showing posts with label sql course. Show all posts
Showing posts with label sql course. Show all posts

Friday, December 29, 2017

How to create Roman Numerals 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 

Result

Saturday, December 23, 2017

IF / Else IF Condition in MSSQL

IF / Else IF Condition in MSSQL


-- HOW TO USE IF / ELSE IF CONDITION IN SQL

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



Thursday, December 21, 2017

How to change Schema Name in SQL

Below Query for change you table schema name from eg. dbo. to test.

ALTER SCHEMA YourSchemaName TRANSFER dbo.YourTableName

-- it will change your schema name from "dbo" to "YourSchemaName"

Saturday, December 9, 2017

How to get SQL database connection string in 5 simple steps

Step 1 : First Open Server Explorer in your Visual Studio IDE


Step 2 : Now click on + button for open connection dialog


Step 3 : now paste your Server Name for get database list



Step 4 : when you paste your server name 1 Dropdown list is open for select database now select your database


Step 5 : now click on Advance button and get your connection string



Happy developing....

SQL Datatype

SQL DataType

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

How to Install SQL Sever 2008 R2?

How to Install SQL Sever 2008 R2?

=>   Sql Server Installation Step Follow Bellow : - 

1) First of all download sql server management studio 2008 then click setup see image 


2) Second step display installation dialog box see image


3) Third step display SQL Server Installation Center Then select "New Installation or add features to an existing installation" Text click see image



4) Then display setup support  rules dialog box see image


5) This step is display license terms then by default two checkbox is unselected display see image


6) This step is select two checkbox then enable next button see image


7) This step is display feature selection then click next button see image


8) This step is display error reporting dialog then click next button see image



9) This step is display complete installation see image 


10) This step is display your setup is ready to user create new database see image



How to setup in visual studio 2013,2017 ?

How to setup in visual studio 2013,2017

                                                                   This article is explain how to setup in visual studio 2013.First of all download visual studio 2013 setup then follow step below.

1) First of all setup double click 


2) Then open visual studio 2013 dialog box then click continue button show below image.


3) Third step is by default path is set "C:\Program Files\Microsoft Visual Studio 12.0". it can change path and set new path otherwise default path store all file and setup data.

                                         Third step display "I Agree to the License Terms and Privacy Policy"
Checkbox by default un-selected display then select checkbox to display Next button.see image



4) Then Click Next Button see Image.


5) Fifth step display "Optional features to install" by default all selected. then click Install Button.See image



6) Six step is display progress bar in i think 40 minute process to install visual studio 2013 data.waiting in 40 minutes see image

7) Congratulation your setup is completed install and display dialog see image

8) Then click "LAUNCH" text 

9) Nine step to display  "Welcome Sign in to Visual Studio." then click "Not now,Maybe later " text.see image


10) This step is choose your color theme.there are three theme display
  1.  Blue
  2. Dark
  3. Light
Select a Blue color theme then click Start Visual Studio. see image


11) This step is display waiting few minute see image


12) Finally all process is finish display visual studio 2013 dialog.your are create own web application,Software etc.see image

Tuesday, March 24, 2015

How To Update One DataBase Table To Another DataBase Table In SQL

USE db1
go
UPDATE t1 SET DateOfRegistration = t2.DateOfRegistration
FROM db1.TableName1 t1
JOIN db2.TableName2 t2
ON t1.IDP = t2.IDP

How To Copy One DataBase Table To Another DataBase Table In SQL

SELECT * INTO dbStudent.dbo.tblSetting FROM dbLive.dbo.tblSetting

How To Search Text In Store Procedure SQL

SELECT R.SPECIFIC_NAME,R.ROUTINE_DEFINITION FROM
dbstud.INFORMATION_SCHEMA.ROUTINES R
WHERE UPPER(R.ROUTINE_DEFINITION) LIKE '%' + UPPER('DELETE') + '%'

How To Search SQL Table Use In Store Procedure

SELECT O.NAME FROM SYSCOMMENTS C
INNER JOIN SYSOBJECTS O ON C.ID = O.ID
WHERE TEXT LIKE '%TableName%'

How To Get All Store Procedure In Current SQL DataBase

SELECT * FROM SYSOBJECTS WHERE XTYPE='P'

How Search Text In SQL Storeprocedure

SELECT * FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECTPROPERTY(OBJECT_ID(SPECIFIC_NAME),'IsMSShipped') =0
AND OBJECT_DEFINITION(OBJECT_ID(SPECIFIC_NAME)) like '%Procedure Name%'
AND ROUTINE_TYPE='PROCEDURE'

Friday, July 12, 2013

Monday, June 10, 2013

How Find Column Name Use in Which Table Using SQL

select so.name
from sysobjects so inner join syscolumns sc
ON so.id = sc.id where sc.name = 'Name'

Result :

tblStudent
tblEtc

How to Conver Upper Case to First Letter Capital of Each Word in SQL

SELECT dbo.ProperCase('Hardik Deshani')

Result : Hardik Deshani

Create Function This Function:

CREATE FUNCTION [dbo].[ToTitleCase]
(@OriginalText VARCHAR(8000))
RETURNS VARCHAR(8000) 
BEGIN
DECLARE @CleanedText VARCHAR(8000)
;with
  a1 as (select 1 as N union all select 1 union all
         select 1      union all select 1 union all
         select 1      union all select 1 union all
         select 1      union all select 1 union all
         select 1      union all select 1),
  a2 as (select 1 as N from a1 as a cross join a1 as b),
  a3 as (select 1 as N from a2 as a cross join a2 as b),
  a4 as (select 1 as N from a3 as a cross join a2 as b),
  Tally as (select top (len(@OriginalText)) row_number() over (order by N) as N from a4)
 
SELECT @CleanedText = ISNULL(@CleanedText,'') + 
     --first char is always capitalized?
CASE WHEN Tally.N = 1 THEN UPPER(SUBSTRING(@OriginalText,Tally.N,1))
     WHEN SUBSTRING(@OriginalText,Tally.N -1,1) = ' '  THEN UPPER(SUBSTRING(@OriginalText,Tally.N,1))
     ELSE LOWER(SUBSTRING(@OriginalText,Tally.N,1))
END
    
FROM Tally WHERE Tally.N <= LEN(@OriginalText)           
               
RETURN @CleanedText
END