How to create Temptable on SQL server

 Basically Temporary table  in SQL server exists Temporary in Database Server.Which is used  to store Subset of Data from other Table.

Mostly Temp table is useful for the store procedure query where we store large amount of record in it and accordingly fetch data from it .
Lets See How to  create Temporary  table  on SQL Server


 
  First We  we will use drop command to delete any table exist from that name it will delete  automatically if SQL  connection breaks

  Drop table if exists  #Temptable


Now we will Create Temporary table  by using the same name i.e use in above query for drop  #Temptable.

Basically we use # as Prefix in the name of Temporary Table


   create Table  #Temptable
   (
   UserID int,
   UserName nvarchar(32),
   Address nvarchar(64),
   )


We will insert any data in that table and use it  accordingly.
Lets See how we will use it in Store Procedure

  
 create proc Sp_GetEmpDetails
  as
  begin
  Drop table if exists  #Temptable
  create Table  #Temptable
   (
   UserID int,
   UserName nvarchar(32),
   Address nvarchar(64),
   PinCode nvarchar(16),
  Designation nvarchar(16),,
   Company nvarchar(16), 
   )
  insert into #Temptable
 select Username,Address,PinCode ,Designation ,Company 
 from yourtablename
  cross join DesignationtableName
  cross join CompanytableName 


  select * from #Temptable
  end


How to select First letter of first name and First letter of Last Name from Name in Sql


To Get First letter of first name and First letter of Last Name from Name  in Sql server we have to use 

PATINDEX and CHARINDEX

let see how I got it.



  
declare
@var varchar(50),
@lastname  varchar(50)
declare @start INT = 1
declare @Last INT = 1
set @var = 'Gunjan Kumar '

SELECT @start = PATINDEX('%[A-Z][a-z]%',@var)
SELECT @lastname = PATINDEX('%[A-Z][a-z]%',@var)

set @lastname= (SELECT  SUBSTRING(@var, CHARINDEX(' ', @var) +1, 20))
select SUBSTRING(@var, @Last, 1)+
 SUBSTRING(@lastname, @Last, 1)splitname


And The Result looks like


   splitname

   GK


Get Id of the row on click of Datatable in Angular

To get id of  each row of  the material Datatable in angular  we need assign id of each row on its (td) or there must be id on the Datasource.

lets see





 <ng-container matColumnDef="name">
                  <th mat-header-cell *matHeaderCellDef>EmployeeID</th> 

        <td mat-cell *matCellDef="let element"> {{element.EmployeeID}} </td>
                </ng-container>




In the above we have give id to all its row of the table
After this we have to add click function on table row i.e like below


   

<tr mat-row *matRowDef="let row; columns: displayedColumns;" (click)="getEmployeeID(row.EmployeeID)"></tr>




On Click function we will get the Id of each row and use it accordingly