Share Blog

Tuesday, April 05, 2016

How to Reverse Each Word in a String Using C#

Example :Sunil Kumar

Reverse String :linuS ramuK

Write a Code


static void Main(string[] args)
        {
            string str = "Sunil Kumar";
            var reversedWords = string.Join(" ",
      str.Split(' ')
         .Select(x => new String(x.Reverse().ToArray()))
         .ToArray());
            Console.WriteLine(reversedWords);
            Console.ReadLine();


        }

Result 




In other words:
·         Split on spaces
·         For each word, create a new word by treating the input as a sequence of characters, reverse that sequence, turn the result into an array, and then call the string(char[]) constructor
·         Depending on framework version, call ToArray() on the string sequence, as .NET 4 has more overloads available
·         Call string.Join on the result to put the reversed words back together again.

Friday, January 29, 2016

Select first,Second Row Data In SQL Server

How to display serial number or we can say record/row number Data In sql server




SELECT TOP 1 * FROM DigiNews WHERE ID NOT IN ( SELECT TOP 1 ID FROM DigiNews ORDER BY ID desc )ORDER BY ID desc


Local and Global Temporary Table in SQL Server

local Temporary Table:A local temporary table, #tableName, exists only for the duration of a user session or the table that created the temporary table.When the user logs off or when the procedure that created the table completes, the local temporary table is lost.


create table #Employee
(
Id int Primary key Not Null,
Name varchar(150)
)

Insert into #Employee values(1,'Jitu')

select * from #Employee


Global Temporary Table:A global temporary table, ##tableName, also exists for the duration of a user session or the table that created the table.When the last user session that references the table disconnects, the global temporary table is lost.

create table ##Employee
(
Id int Primary key Not Null,
Name varchar(150)
)

Insert into ##Employee values(1,'Hemant')

select * from ##Employee






There are a few characteristics of Global Temporary Tables:
1.   Local Temporary ('#') tables are visible only in the current session; Global Temporary('##') tables are visible to all sessions.

2.   It starts with the single hash value "##" as the prefix of the table name and its name is always unique. There is no random number appended to the name.

3.   Global Temporary Tables are visible to all connections of SQL Server.
4.   Global Temporary Tables are only destroyed when the last connection referencing the table is closed (in which we have created the Global Temporary Table).
5.   You can access the Global Temporary Tables from all connections of SQL Server until the referencing connection is open.





Monday, January 11, 2016

How To Changev Male TO Female and Female To Male Using SQL SERVER

Create Table




 Insert Data in Table




Syntax

select * from Emp

Select id,name,
Case Gender
When 'M' Then 'F'
When 'F' Then 'M'
END

From Emp

Result







Update Male TO Female and Female To Male


UPDATE Emp SET gender =
CASE gender
WHEN 'F' THEN 'Male'
WHEN 'M' THEN 'Female'
ELSE
 gender END


Result