Adds

Thursday, 26 November 2015

Update Name to Title Case in SQL Server using SQL Query




-- User Define Function
Create Function dbo.[UDF_TITLE_CASE]
(
      @String VARCHAR(MAX)  -- Variable for string
)
RETURNS varchar(MAX)
BEGIN
     Declare @Xml XML
     Declare @ProperCase Varchar(Max)
     Declare @delimiter Varchar(5)
     Set @delimiter=' '
     SET @Xml = cast(('<A>'+replace(@String,@delimiter,'</A><A>')+'</A>') AS XML)

     ;With CTE AS (SELECT A.value('.', 'varchar(max)') as [Column]
      FROM @Xml.nodes('A') AS FN(A) )
      Select @ProperCase =Stuff((Select ' ' + UPPER(LEFT([Column],1))
      + LOWER(SUBSTRING([Column], 2 ,LEN([Column]))) from CTE
      for xml path('') ),1,1,'')

RETURN (@ProperCase)
END
GO
-- For Example :
SELECT dbo.[UDF_PROPER_CASE]([StudentInfo_Name]) as [Student Name]
from [dbo].[Tbl_StudentInformation]
GO

SELECT [StudentInfo_Name] as [Student Name]
from [dbo].[Tbl_StudentInformation]
GO


update [dbo].[Tbl_StudentInformation]
set [StudentInfo_Name]=dbo.[UDF_PROPER_CASE]([StudentInfo_Name])

Wednesday, 25 November 2015

Create a user & grant that user to a specific Database



--Step 1: (create a new user)
create LOGIN hello WITH PASSWORD='foo', CHECK_POLICY = OFF;


-- Step 2:(deny view to any database)
USE master;
GO
DENY VIEW ANY DATABASE TO hello;


 -- step 3 (then authorized the user for that specific database , you have to use the  master by doing use master as below)
USE master;
GO
ALTER AUTHORIZATION ON DATABASE::khsk_db TO hello;
GO

Friday, 21 August 2015

Crystal Report View PDF in Browser



using System.IO;



MemoryStream oStream;
oStream = (MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "filename=" + FileName + ".pdf");
Response.BinaryWrite(oStream.ToArray());
Response.End();

Saturday, 20 June 2015

ASP.NET C# StopWatch



using System.Diagnostics;

Stopwatch sw = Stopwatch.StartNew();

 Your Process Start
Your Process End
string second = sw.ElapsedMilliseconds.ToString();
sw.Stop();

Wednesday, 11 March 2015

Get SQL Server Use Which Port Using a Query




SELECT DISTINCT
local_tcp_port
FROM sys.dm_exec_connections
WHERE local_tcp_port IS NOT NULL



This is for specific database


SELECT DISTINCT
    local_tcp_port
FROM sys.dm_exec_connections
WHERE local_tcp_port IS NOT NULL
USE master
GO
xp_readerrorlog 0, 1, N'Server is listening on'
GO