Hi,
We are happy to inform that we had launched our own site http://dotnetmirror.com
we are moving all of these blog content. please visit the site.
Thanks,
Webmaster
14 December 2012
02 November 2012
GET/Remove the last character from a string in SQL Server
In some of cases we need remove last character from the string.In this tip we will see how to get and remove last character in string.
Sample string: 'DotNetMirror,'
Now we will remove , from the string.
Get Last Char in string:
Sample string: 'DotNetMirror,'
Now we will remove , from the string.
Get Last Char in string:
Declare @STRING varchar(100)
set @STRING='DotNetMirror,'
select RIGHT(@String, 1)
Remove the last char(comma) in string :
IF(LEN(@String)> 0 AND RIGHT(@String, 1) = ',')
BEGIN
select substring(@String, 1, (len(@String) - 1)) --or
SET @String = LEFT(@String, LEN(@String) - 1)
END
select @String
Tags :
SQL Server,
Tip
15 September 2012
Iterating/Looping through rows without using cursors in Sql server
In this snippet we will see how to iterating the table rows data with out using cursor in SQL server.
set nocount on
go
declare @tempEmpTable table(EmpID int , EmpName nvarchar(100))
declare
@varEmpID int,
@varEmpName nvarchar(100)
insert into
@tempEmpTable
select 1, '1st Employee' union
all
select 2, '2nd Employee' union
all
select 3, '3rd Employee' union
all
select 4, '4th Employee' union
all
select 5, '5th Employee' union
all
select 6, '6th Employee' union
all
select 7, '7th Employee' union
all
select 8, '8th Employee' union
all
select 9, '9th Employee'
select top 1
@varEmpID = EmpID,
@varEmpName = EmpName from
@tempEmpTable
while @varEmpID is
not null
begin
print
@varEmpName
delete @tempEmpTable where
@varEmpID = EmpID
set
@varEmpID = null
select
top 1 @varEmpID =
EmpID, @varEmpName =
EmpName from
@tempEmpTable
end
|
Output:
1st
Employee
2nd
Employee
3rd
Employee
4th
Employee
5th
Employee
6th
Employee
7th
Employee
8th
Employee
9th
Employee
|
Tags :
Snippet,
SQL Server
12 September 2012
javascript not setting the hidden field value in ASP.NET
Today when i tried to change the value of hidden filed in java script, its not setting the value. I am using master page for an ASPX page.
<asp:HiddenField ID="hdnTest"
runat="server"
Value="Before JS
Call" />
In java script method, when I try to assign the value it’s not
getting replaced with new value.
document.getElementById('<%=hdnTest.ClientID%>').value = 'After JS Call';
document.getElementById('ContentPlaceHolder1_hdnTest').value = 'After JS Call';
and it worked out.
Not sure with the reason but its resolved!
Tags :
ASP.NET,
ErrSol,
Java script
06 September 2012
Rollback Transaction for table variable in sql server
Table variable is special kind of data type which will store
result set and the data will returned for processing. Table variable can be
used in store procedures and functions.
Table variables have limited scope and data will be stored
in temporary storage so they are not affected with transaction roll backs.
In the below script we will
see practically how rollback behaves for table variable.
Tags :
Article,
SQL Server
03 September 2012
convert IP address to binary format using IPAddress Class in C#
In this snippet we will see how to convert an IP
address to binary format using System.Net.IPAddress class.
static List<string>
ConvertIPAddressToBinary(string input)
{
IEnumerable<string>
binaries= IPAddress.Parse(input).GetAddressBytes().Select(
x=> Convert.ToString(Convert.ToInt32(x), 2).PadLeft(8, '0'));
return binaries.ToList();
}
static
void Main()
{
List<string>
listBinaries = ConvertIPAddressToBinary(“192.168.0.1”)
foreach (string
binary in listBinaries)
{
Console.Write(binary + "
");
}
}
|
Output : 11000000 10101000 00000000 00000001
|
IPAddress class contains the address of a computer on an IP network and supports IPv4 or IPv6.