ghTemp123 / wiresharkplugin

Automatically exported from code.google.com/p/wiresharkplugin
0 stars 0 forks source link

Convert multiple rows into one with comma as separator #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If I issue SELECT username FROM Users I get this result:

username
--------
Paul
John
Mary

but what I really need is one row with all the values separated by comma, like 
this:

Paul, John, Mary

How do I do this?

create table #user (username varchar(25))

insert into #user (username) values ('Paul')
insert into #user (username) values ('John')
insert into #user (username) values ('Mary')

declare @tmp varchar(250)
SET @tmp = ''
select @tmp = @tmp + username + ', ' from #user

select SUBSTRING(@tmp, 0, LEN(@tmp))

Original issue reported on code.google.com by cn.wei.hp@gmail.com on 7 Dec 2010 at 9:48

GoogleCodeExporter commented 9 years ago
Retrieving Data as XML from SQL Server

Original comment by cn.wei.hp@gmail.com on 7 Dec 2010 at 10:12

GoogleCodeExporter commented 9 years ago
// Create the query
var custs = from c in XElement.Load("Customers.xml").Elements("Customers")
          select c ;

// Execute the query
foreach (var customer in custs)
{
     Console.WriteLine(customer);
}

//Pause the application
Console.ReadLine(); 

where c.Element("Country").Value == "Italy"

Original comment by cn.wei.hp@gmail.com on 7 Dec 2010 at 10:24

GoogleCodeExporter commented 9 years ago
    static void Main(string[] args)
    {
        WriteRssToDb();
        Console.ReadLine();
    }

    private static void WriteRssToDb()
    {
        XDocument feed = XDocument.Load("http://weblogs.asp.net/scottgu/rss.aspx");
        SampleGayaniDataContext dbContext = new SampleGayaniDataContext();
        var feedpost = from post in feed.Descendants("item")

        select new RssFeed
        {
            Tile = post.Element("title").Value,
            Date = DateTime.Parse(post.Element("pubDate").Value)
        };

        dbContext.RssFeeds.InsertAllOnSubmit(feedpost);
        dbContext.SubmitChanges();
        Console.WriteLine("Successfully inserted, Check your database.");
    }

Original comment by cn.wei.hp@gmail.com on 7 Dec 2010 at 10:24

GoogleCodeExporter commented 9 years ago
Create the XML Mapping File

<?xml version="1.0" encoding="utf-8" ?>
<Database Name="AdventureWorksLT" 
xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007">
  <Table Name="SalesLT.Customer" Member="Model.Customer">
    <Type Name="Model.Customer">
      <Column Name="CustomerID" Member="CustomerID" IsDbGenerated="true" IsPrimaryKey="true" />
      <Column Name="Title" Member="Title" />
      <Column Name="FirstName" Member="FirstName" />
      <Column Name="LastName" Member="LastName" />
      <Column Name="ModifiedDate" Member="ModifiedDate" />
    </Type>
  </Table>
  <Function Name="dbo.ap_GetCustomerByLastName" Method="GetCustomerByLastName">
    <Parameter Name="lastNameLetter" Parameter="LastNameLetter" />
    <ElementType Name="Model.Customer" />
  </Function>
</Database>

Original comment by cn.wei.hp@gmail.com on 7 Dec 2010 at 10:31

GoogleCodeExporter commented 9 years ago
<?xml version="1.0" encoding="UTF-8"?>
<tables>
   <table name="Author">
     <field name="first" type="text"/>
     <field name="last" type="text"/>
   </table>
   <table name="Publisher">
     <field name="name" type="text"/>
     <field name="last" type="text"/>
   </table>
   <table name="Book">
     <field name="name" type="text"/>
     <field name="author" type="id"/>
     <field name="publisher" type="id"/>
   </table>
</tables>

Original comment by cn.wei.hp@gmail.com on 7 Dec 2010 at 11:42

GoogleCodeExporter commented 9 years ago
这段简单的 XML 
脚本定义了三个数据库表及其字段:Author(作者)、Publisher��
�出版商)和 Book(图书)。

Original comment by cn.wei.hp@gmail.com on 7 Dec 2010 at 11:43