I want to store a character in table like the followed details,
In my table am having three columns. and am giving the input like "Shanmuga Priya Nadimuthu" means it will store in that table at first column "Shanmuga" should save, and in second column "Priya" sholud enter, and in third column "Nadimuthu" should enter.
I dono how to write query for that. Can any please help me to resolve this problem. It is an immediate issue.
But how can i use that in query. Since am new to sql it will be better, can u please ellaborate me about the query.
Hi Shanmugapriya,
If you are consuming the name from front-end (from the user from a web-page) , you may have three differant text-boxes like, one for "First Name' one for 'Middle Name' and the third for the 'Last Name'
You may split the string and can retrieve all your 'Parameters'
//Assuming that you're getting that name from a textbox
string[] SomeStringArray = texbox1.text.Split(' ');
//if not, and you already are having the value in a string variable, say 'strFullName' then ...
string[] SomeStringArray = strFullName.Split(' ');
//now that you already have got the first mid and last separately in the string array you may build your query like this
string strInsertQuery = "INSERT INTO TABLE_NAME (COL_FIRSTNAME, COL_MIDLLENAME, COL_LASTNAME) VALUES (";
foreach (string s in SomeStringArray )
strInsertQuery += "'" + s + "', ";
//you would have an extra comma at the end, remove the last character of the string
strInsertQuery.Remove(str.Length - 1, 1);
strInsertQuery += ")";
//When I ran this code I Was getting something like this ...
//INSERT INTO TABLE_NAME (COL_FIRSTNAME, COL_MIDLLENAME, COL_LASTNAME) VALUES ('Amelia' + 'Eirwen' + 'Goudling')
But am having only one text box for users to enter their value. At the same time i need to write a query to insert the data into table which contains three seprate columns. This should not achieved through the Programming languages.
This should not achieved through the Programming languages.
No. It's not possible to achieve without programming languges. How do you suppose your webapplication to communicate with SQL server without a programming language?
Thanks for your reply. But i need to write query. I dont have front end and all. My senior gave me task to achieve this in Sql Server query window itself.
For Example,
Input is 'Shanmuga Priya Nadimuthu' there are three columns in DB like Fname,Mname,Lname. By writing a query using substring concept the value has to store in table like the following format. 'Shanmuga --- under column Fname , Priya -- Under the column
Mname, Nadimutu -- under the column Lname.
Shanmugapriy...
Member
213 Points
328 Posts
Sql Query
Dec 24, 2012 05:11 PM|LINK
Hi friends,
I want to store a character in table like the followed details,
In my table am having three columns. and am giving the input like "Shanmuga Priya Nadimuthu" means it will store in that table at first column "Shanmuga" should save, and in second column "Priya" sholud enter, and in third column "Nadimuthu" should enter. I dono how to write query for that. Can any please help me to resolve this problem. It is an immediate issue.
Thanks in advance.
aarsh
Participant
1547 Points
435 Posts
Re: Sql Query
Dec 24, 2012 05:18 PM|LINK
You may use String.Split and use " " (a space) as your delimiter
Shanmugapriy...
Member
213 Points
328 Posts
Re: Sql Query
Dec 24, 2012 05:29 PM|LINK
Thanks for your Reply friend. But how can i use that in query.
Since am new to sql it will be better, can u please ellaborate me about the query.
Afzaal.Ahmad...
Contributor
2759 Points
1060 Posts
Re: Sql Query
Dec 24, 2012 05:56 PM|LINK
Why dont you use three inputs?
http://stackoverflow.com/questions/2647/split-string-in-sql
This thread has the same question. Please read it
~~! FIREWALL !~~
aarsh
Participant
1547 Points
435 Posts
Re: Sql Query
Dec 24, 2012 06:40 PM|LINK
Hi Shanmugapriya,
If you are consuming the name from front-end (from the user from a web-page) , you may have three differant text-boxes like, one for "First Name' one for 'Middle Name' and the third for the 'Last Name'
You may split the string and can retrieve all your 'Parameters'
//Assuming that you're getting that name from a textbox string[] SomeStringArray = texbox1.text.Split(' '); //if not, and you already are having the value in a string variable, say 'strFullName' then ... string[] SomeStringArray = strFullName.Split(' '); //now that you already have got the first mid and last separately in the string array you may build your query like this string strInsertQuery = "INSERT INTO TABLE_NAME (COL_FIRSTNAME, COL_MIDLLENAME, COL_LASTNAME) VALUES ("; foreach (string s in SomeStringArray ) strInsertQuery += "'" + s + "', "; //you would have an extra comma at the end, remove the last character of the string strInsertQuery.Remove(str.Length - 1, 1); strInsertQuery += ")"; //When I ran this code I Was getting something like this ... //INSERT INTO TABLE_NAME (COL_FIRSTNAME, COL_MIDLLENAME, COL_LASTNAME) VALUES ('Amelia' + 'Eirwen' + 'Goudling')*** You may refer the detailed demo located at : http://sdrv.ms/VrCoy5 ***
Shanmugapriy...
Member
213 Points
328 Posts
Re: Sql Query
Dec 25, 2012 03:51 AM|LINK
Thanks For your reply friends,
But am having only one text box for users to enter their value. At the same time i need to write a query to insert the data into table which contains three seprate columns. This should not achieved through the Programming languages.
Can anyone please guide me.
Thanks in advance.
AL MUBARAK
Member
164 Points
115 Posts
Re: Sql Query
Dec 25, 2012 05:09 AM|LINK
Hai,
what does mean text for users to enter thier value At the same time i need how write query .?
Could please tell me clearly, so i can help you out.
Al Mubarak
Ruchira
All-Star
44216 Points
7184 Posts
MVP
Re: Sql Query
Dec 25, 2012 05:51 AM|LINK
Hello,
No. It's not possible to achieve without programming languges. How do you suppose your webapplication to communicate with SQL server without a programming language?
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.Shanmugapriy...
Member
213 Points
328 Posts
Re: Sql Query
Dec 25, 2012 06:13 AM|LINK
Hi Ruchira,
Thanks for your reply. But i need to write query. I dont have front end and all. My senior gave me task to achieve this in Sql Server query window itself.
For Example,
Input is 'Shanmuga Priya Nadimuthu' there are three columns in DB like Fname,Mname,Lname. By writing a query using substring concept the value has to store in table like the following format. 'Shanmuga --- under column Fname , Priya -- Under the column Mname, Nadimutu -- under the column Lname.
Can please guide me to write the query.
KiaranNafade
Member
136 Points
59 Posts
Re: Sql Query
Dec 25, 2012 07:32 AM|LINK
simple
string[] striarr;
string fullname = "first middle last";
striarr = fullname.Split(' ');
foreach (string sdsd in striarr)
{
ListBox1.Items.Add(sdsd.ToString());
}
string fname = ListBox1.Items[0].Value;
string sname = ListBox1.Items[1].Value;
string lname = ListBox1.Items[2].Value;
cmd = new SqlCommand("insert into table1('" + fname + "','" + sname + "','" + lname + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
please Click "MARK A ANSWER" if helps for you