erkaMedlem sedan dec. 19994 597 inlägg Kollat igenom men inte hittat hur man löser det på ett smidigt sätt, jag vill att den ska bara skriva ut en topic samt länken om han hittar flera i samma topicsubject, repliemessage, topicmessage och sen hoppa till nästan, någon form av distinct select satts alltså..
Nu ser koden ut
strSQL = "SELECT dbo.Forum.ForumID, dbo.Replies.ReplieId, dbo.Replies.TopicID, dbo.Replies.ReplieBy, dbo.Replies.ReplieMessage, dbo.Replies.ReplieDate, "_
&"dbo.Topics.TopicID, dbo.Topics.ForumID, dbo.Topics.TopicBy, dbo.Topics.TopicSubject, dbo.Topics.TopicMessage, dbo.Topics.TopicDate "_
&"FROM dbo.Forum INNER JOIN dbo.Topics ON dbo.Forum.ForumID = dbo.Topics.ForumID INNER JOIN dbo.Replies ON dbo.Topics.TopicID = dbo.Replies.TopicID "_
&"WHERE dbo.Topics.ForumID = "& strForumId &" AND dbo.Forum.ForumID = "& strForumId &" "_
&"AND dbo.Replies.ReplieMessage LIKE '%" & strSearch & "%' OR dbo.Topics.TopicSubject LIKE '%" & strSearch & "%' "_
&"OR dbo.Topics.TopicMessage LIKE '%" & strSearch & "%'"
Men nu får jag ju fram flera som ni kanske ser av koden. Någon som har en bra lösning av mitt problem ?
------------------
Real mad hiphop flavaz kickin' it right from tha street without no FEAR, Yo !
LarsGMedlem sedan dec. 200012 465 inlägg Jag säger bara ett ord:
använd union
------------------
essentitia preter non sans multiplicandum
erkaMedlem sedan dec. 19994 597 inlägg hmm ser ju det nu :) vad tror du om den här
strSQL ="SELECT DISTINCT dbo.Forum.ForumID, dbo.Forum.ForumName, dbo.Topics.TopicID, dbo.Topics.ForumID, dbo.Topics.TopicSubject, "_
&"dbo.Topics.TopicMessage, dbo.Topics.TopicDate FROM dbo.Forum INNER JOIN dbo.Topics ON dbo.Forum.ForumID = dbo.Topics.ForumID "_
&"WHERE dbo.Forum.ForumID = "&strForumId&" AND (dbo.Topics.TopicSubject LIKE '%" & strSearch & "%' OR dbo.Topics.TopicMessage LIKE '%" & strSearch & "%' ) "_
&"UNION "_
&"SELECT DISTINCT dbo.Forum.ForumID, dbo.Forum.ForumName, dbo.Replies.ReplieId, dbo.Replies.TopicID, dbo.Replies.ReplieBy, dbo.Replies.ReplieMessage, "_
&"dbo.Replies.ReplieDate FROM dbo.Forum CROSS JOIN dbo.Replies "_
&"WHERE dbo.Forum.ForumID = "& strForumId &" AND dbo.Replies.ReplieMessage LIKE '%" & strSearch & "%'"
Funkar verkar den göra men är den ful :e
tack larsg
------------------
Real mad hiphop flavaz kickin' it right from tha street without no FEAR, Yo !
LarsGMedlem sedan dec. 200012 465 inlägg Om den fungerar så är det väl okej.
Om du använder union så behöver du inte ha distinct med då union innebär att man tar bort alla duplikat från resultatet.
------------------
essentitia preter non sans multiplicandum
erkaMedlem sedan dec. 19994 597 inlägg stötte på problem nu, den plockar inte ut rätt. Det är ju ett forum där jag har 3 tabeller
Forum (där jag behöver ha ut)
ForumId
Replies (där jag behöver ha ut)
TopicID
ReplieMessage
ReplieDate
Topics (där jag behöver ha ut)
TopicId
ForumId
TopicSubject
TopicMessage
TopicDate
Problemet är att det inte fungerar med en union eftersom jag måste ha lika många fält och av samma typ i en union. Vad ska man göra istället ?
------------------
Real mad hiphop flavaz kickin' it right from tha street without no FEAR, Yo !
LarsGMedlem sedan dec. 200012 465 inlägg Du kan ju alltid lägga till konstanter i ena delen
select a,b,c from t1
union
select a,b,'x' from t2
pss kan du alltid få till att det är lika många och av samma typ.
------------------
essentitia preter non sans multiplicandum
erkaMedlem sedan dec. 19994 597 inlägg Problemet blir att jag skriver ut det så här
<%
strSQL="SELECT dbo.Forum.ForumID, dbo.Topics.TopicID, dbo.Topics.ForumID, dbo.Topics.TopicSubject, dbo.Topics.TopicMessage, "_
&"dbo.Topics.TopicDate FROM dbo.Forum INNER JOIN dbo.Topics ON dbo.Forum.ForumID = dbo.Topics.ForumID "_
&"WHERE dbo.Forum.ForumID = "&strForumId&" AND (dbo.Topics.TopicSubject LIKE '%" & strSearch & "%' OR dbo.Topics.TopicMessage LIKE '%" & strSearch & "%' ) "_
&"UNION "_
&"SELECT dbo.Forum.ForumID, dbo.Replies.ReplieId, dbo.Replies.TopicID, dbo.Replies.ReplieBy, dbo.Replies.ReplieMessage, dbo.Replies.ReplieDate "_
&"FROM dbo.Forum CROSS JOIN dbo.Replies "_
&"WHERE dbo.Forum.ForumID = "& strForumId &" AND dbo.Replies.ReplieMessage LIKE '%" & strSearch & "%'"
Set RS = Connect.Execute(strSQL)
If Rs.Eof Then
Response.Write"Hittade NADA"
Rs.Close
Set RS = Nothing
Else
Dim ArrRs, i
ArrRs = Connect.Execute(strSQL).getrows()
for i = 0 to ubound(ArrRs,2)
%>
<br><a href="ShowTopic.asp?ForumId=<%=ArrRs(0,i)%>&TopicId=<%=ArrRs(2,i)%>"><%=ArrRs(4,i)%></a> <%=Left(ArrRs(5,i),16)%> : <%=ArrRs(5,i)%>
<br>
<%
Next
End If
Connect.Close
Set Connect = Nothing
%>
Och länkarna blir rätt på vissa men vissa får helt fel TopicId. Vad fean beror det på tro ?
------------------
Real mad hiphop flavaz kickin' it right from tha street without no FEAR, Yo !
erkaMedlem sedan dec. 19994 597 inlägg Glöm det, hade ju skrivit dem på fel plats i de båda sattserna :) återkommer om jag stöter på mer probs.danke! trevlig helg föresten, ska jobba till 9 ikväll, suck :e
------------------
Real mad hiphop flavaz kickin' it right from tha street without no FEAR, Yo !
LarsGMedlem sedan dec. 200012 465 inlägg Dags att säga det nu. Jag hade redan lagt ner 1 minut på att hitta det.
Varför har du inget villkor på replies i den andra union-grenen?
(Sats stavas med 1 t)
------------------
essentitia preter non sans multiplicandum
[Redigerat av LarsG den 12 okt 2001]
erkaMedlem sedan dec. 19994 597 inlägg Det är bara ett litet problem nu, jag har pulat å fulat med unionen.
nu ser den ut
strSQL="SELECT DISTINCT dbo.Forum.ForumID, dbo.Topics.TopicID, dbo.Topics.ForumID, dbo.Topics.TopicSubject, dbo.Topics.TopicMessage, "_
&"dbo.Topics.TopicDate FROM dbo.Forum INNER JOIN dbo.Topics ON dbo.Forum.ForumID = dbo.Topics.ForumID "_
&"WHERE dbo.Forum.ForumID = "&strForumId&" AND (dbo.Topics.TopicSubject LIKE '%" & strSearch & "%' OR dbo.Topics.TopicMessage LIKE '%" & strSearch & "%' ) "_
&"UNION "_
&"SELECT DISTINCT dbo.Forum.ForumID, dbo.Replies.TopicID, dbo.Topics.ForumID, dbo.Topics.TopicSubject, dbo.Replies.ReplieMessage, dbo.Topics.TopicDate "_
&"FROM dbo.Forum INNER JOIN dbo.Topics ON dbo.Forum.ForumID = dbo.Topics.ForumID INNER JOIN dbo.Replies ON dbo.Topics.TopicID = dbo.Replies.TopicID "_
&"WHERE dbo.Forum.ForumID = "& strForumId &" AND dbo.Replies.ReplieMessage LIKE '%" & strSearch & "%'"
Har märkt att den skriver ut 2 av sakerna ibland, jag tror det har att göra med att jag har stält något fält fel men ser inte hur jag annars ska lösa det. Titta på det om du har tid och ork ;)
------------------
Real mad hiphop flavaz kickin' it right from tha street without no FEAR, Yo !