Archive for April, 2007

Deleting duplicate rows when there is no primary key

Posted in Sql Server 2000, Sql server 2005 on April 30, 2007 by bimal4u

set nocount on
create table #tbFruit (Fruit varchar(20))
insert into #tbFruit (Fruit) values (‘apple’)
insert into #tbFruit (Fruit) values (‘apple’)
insert into #tbFruit (Fruit) values (‘apple’)
insert into #tbFruit (Fruit) values (‘apple’)
insert into #tbFruit (Fruit) values (‘orange’)
insert into #tbFruit (Fruit) values (‘orange’)
insert into #tbFruit (Fruit) values (‘orange’)

create table #tbFruitsWithDupes (DupeID int identity, Fruit varchar(20), DupeCount int)

insert into #tbFruitsWithDupes (Fruit, DupeCount)
 select Fruit, count(*) DupeCount from #tbFruit
 group by Fruit having count(*) > 1

declare @x int, @max int, @Fruit varchar(20), @DupeCount int

select @x = 1, @max = max(DupeID) from #tbFruitsWithDupes

while (@x <= @max)
 begin
  select @Fruit = Fruit, @DupeCount = DupeCount – 1
   from #tbFruitsWithDupes Where DupeID = @x

  set rowcount @DupeCount

  delete from #tbFruit where Fruit = @Fruit

  select @x = @x + 1
 end

select * from #tbFruit

drop table #tbFruit
drop table #tbFruitsWithDupes

For Reference please see this link : http://www.xaprb.com/blog/2006/10/09/how-to-find-duplicate-rows-with-sql/

Creating text images

Posted in C# 2.0, Net 2.0 on April 14, 2007 by bimal4u

http://www.zedilabs.com/aspnet/fonternet/font.html

Top 10 new features in SQL Server 2005

Posted in Sql server 2005 on April 3, 2007 by bimal4u

Top 10 features

Other Reference http://www.developer.com/db/article.php/3512126

Binary vs. xml serialization performance

Posted in C# 2.0, Net 2.0 on April 3, 2007 by bimal4u

Toshiba Tecra M5 (dual 2Ghz processor, 2Gb memory) an object of type List<object[]> containing 296 “rows” and 18 “columns” with elements of different data types (strings, integers, dates, etc.) takes approximately 14 ms per iteration for binary serialization & de-serialization and 31 ms per iteration for xml serialization & de-serialization.

Summary:  My tests show that, on average, xml serialization is roughly twice that of binary serialization (i.e. binary serialization takes half the time compared to xml serialization).  

Note:  Serialization performance depends on the complexity of the object, so you should do your own tests to get more precise results for your situation

 

Here is the code I used

 

 

Generic Functions for Object ↔ XML Serialization/Deserialization

Posted in C# 2.0, Net 2.0 on April 3, 2007 by bimal4u

public static string ToXml<T>(T source){    string result = null; 

    using (System.IO.StringWriter sw = new System.IO.StringWriter())    {        using (System.Xml.XmlWriter writer = System.Xml.XmlTextWriter.Create(sw, null))        {            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));            serializer.Serialize(writer, source);        } 

        result = sw.ToString();    } 

    return result;            } 

public static T FromXml<T>(string xml){    T result = default(T); 

    if (string.IsNullOrEmpty(xml) == false)    {        using (System.IO.StringReader sr = new System.IO.StringReader(xml))        {            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));            result = (T) serializer.Deserialize(sr);        }    }             

    return result;}