Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,

i have 3 tables:= Contects(Coloum:ContentID(pk) identity,contenttext varchar)

Sentence( Coloumn:SentenceId(pk) identity,Sentencetext varcahr)

Contentsentence(Coloumn: ContentID int (pk),SentenceId int (pk),orderno int)

i want to write insert query that insert record of contenid of content table into Contentsentencetable and sentenceid of sentence table into Contentsentencetable and also give orderno so how can i do that???)

(note:ContentID and SentenceID Are combined Primary key of the ContentSentence Table)

please provide me sql query so i can use it in my code.
Posted
Comments
_Asif_ 2-Mar-15 5:19am    
How do you link a specific Content Id with a Sentence id?

if third table has also its own primary key..than we can use this query for inserting record


Insert into c.contenttext, s.Sentencetext,cs.orderno
FROM Contects c,Sentence s,Contentsentence cs
where c.Contects.ContentID =cs.Contentsentence
And cs.ContentsentenceID=s.SentenceId
 
Share this answer
 
Comments
vatsaldesai 2-Mar-15 5:41am    
i have to insert ContentId & sentenceid into table ContentSentence. ContentId feild get from Content table & sentenceid feild get from sentence table.
vatsaldesai 2-Mar-15 6:05am    
& also i have to add id not text into table hole table has datatype int.
vatsaldesai 2-Mar-15 6:21am    
I have write this queires for above problem and but problem is given that union store value into one coloum not in diffreent coloum so what to do for insert value into diffrerent coloumn: "INSERT INTO ContentSentences(ContentID,SentenceID)(SELECT ContentID FROM Contents WHERE ContentText LIKE '" + dt1.Rows[i]["SentenceText1"].ToString() + "'%) UNION (SELECT SentenceID FROM Sentences SentenceText LIKE '" + dt1.Rows[i]["SentenceText1"].ToString() + "'%)";
Hi,

Find here single query for your requirement

SQL
INSERT INTO Contentsentence(ContentId, SentenceId)
SELECT ContentID,SenetenceId from 
Contects, Sentence
WHERE contenttext='Your Text'
AND Sentencetext='Your Text'
--Kindly note that these where conditions are not enough to select required data and insert it. You have to maintain some relationship between Contects, Sentence table.



Check your requirement and table structure properly.

Hope this will help you.

Cheers
 
Share this answer
 
Comments
vatsaldesai 3-Mar-15 1:58am    
hi magic wonder i have tried your query its not working properly and table have PK_ FK relationship like Contentsentence have relationship with Contents table using ContentID.
Magic Wonder 3-Mar-15 7:41am    
Hi Vatsal,

As i written in my comment that you have to re-think as well re-design table structure.
vatsaldesai 3-Mar-15 8:15am    
yep.. but if you find perfect solution please tell...

Thank You...
Magic Wonder 4-Mar-15 0:45am    
Look i can try the "PERFECT" solution based on your inputs only.
vatsaldesai 4-Mar-15 0:52am    
ok so which inputs you required??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900