9 Replies - 1616 Views - Last Post: 09 August 2010 - 04:22 AM Rate Topic: -----

#1 programmerjiwa  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 29-June 10

sql command for list down sentence

Posted 08 August 2010 - 11:44 PM

hi all...!

i have data in column with name "my name is Peter"..
i want to list down this data using SQL command

like e.g:

my
name
is
Peter

please let me know how to write SQL command..
Thanks

This post has been edited by programmerjiwa: 08 August 2010 - 11:46 PM

Is This A Good Question/Topic? 0
  • +

Replies To: sql command for list down sentence

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 5,979
  • Joined: 08-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 12:18 AM

Hey.

Could you explain that a little better?

Which type of SQL database are you using? (MySQL? M$ SQL Server? etc...)
What does your table look like, exactly? Is the name of the column "my name is Peter" or is that data within a field with another name?

Based just on that description, I would have to say: that's not a "practical" possibility. If those words are truly meant to be individual pieces of data, they should be stored in individual fields. (Not always ideal, granted, but from a design perspective...)

Most SQL servers only have basic string manipulation functionality, and I've never seem one that has built in functions to split a string. (Although, I've never actually had need for it so I may have overlooked it.) You can of course create such a function yourself, but to be honest you would be better of adjusting your approach so that it is not needed.
Was This Post Helpful? 0
  • +
  • -

#3 programmerjiwa  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 29-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 12:30 AM

i using MS SQL Server

Column name: Name
Data : My Name is Peter


after split woul be like this

My
Name
is
Peter
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 5,979
  • Joined: 08-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 12:42 AM

M$ SQL Server has no built in functionality for this, but you can create your own function to do that. (Try a Google search. A LOT of them floating around the interwebs.)

But I still recommend you try to adjust your design so that this is not needed. Can you explain why you need to do this? We might be able to offer alternatives if we knew the whole picture.

This post has been edited by Atli: 09 August 2010 - 12:43 AM

Was This Post Helpful? 0
  • +
  • -

#5 programmerjiwa  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 29-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 12:47 AM

i need to use this for search function(to search by every words)

after split those words i want list it into drop down list

split those data and show in dropdown list
Was This Post Helpful? 0
  • +
  • -

#6 programmerjiwa  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 29-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 12:57 AM

search using drop down list
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 5,979
  • Joined: 08-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 12:59 AM

In that case, you should be using your server-side programming language to do this. Which server-side language are you using? .NET?

You simply query the string unaltered from the SQL server, and use something like String.Split (.Net)) to split it. Then you can just prepare your drop-down like you would normally.

This post has been edited by Atli: 09 August 2010 - 12:59 AM

Was This Post Helpful? 1
  • +
  • -

#8 programmerjiwa  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 29-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 01:32 AM

Yeah...thank you Mr Atli...
the way u told me it working...!
thank you again
Was This Post Helpful? 0
  • +
  • -

#9 programmerjiwa  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 29-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 02:24 AM

hi

i have wrote codes for read text files and view in data grid...

now i add a button to save all data from data grid..
how could i make it..get me some help..

here is the code

<code>

private void btnImport_Click(object sender, EventArgs e)
{
try
{

if (string.IsNullOrEmpty(txtOpenFile.Text.Trim()))
{
MessageBox.Show("Please select file");
return;
}
System.IO.StreamReader sr = new System.IO.StreamReader(txtOpenFile.Text.Trim());
string inputLine = "";

DataTable dt = null;

DataRow row;
while ((inputLine = sr.ReadLine()) != null)
{
string[] array;
array = inputLine.Split(',');

if (dt == null)
{
dt = new DataTable();

foreach (string element in array)
dt.Columns.Add();
}

row = dt.NewRow();

for (int i = 0; i < array.Length; i++)
{
row[i] = array[i];
}

dt.Rows.Add(row);
}

dt.Rows.RemoveAt(0);
dataGridView1.DataSource = dt;

sr.Close();
}
catch (Exception)
{
throw;
}

}
</code>
Was This Post Helpful? 0
  • +
  • -

#10 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 5,979
  • Joined: 08-June 10

Re: sql command for list down sentence

Posted 09 August 2010 - 04:22 AM

It would be better if you ask this question over in the C# forum. It's best not to pile multiple questions into a single thread. Gets cluttered and confusing very fast.

And besides, I have barely touched .Net in years. The C# experts will be able to answer this much better than I can :)

P.S.
Code tags are used like this: [code] ... [code]. (It's not HTML ;))
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1