Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: Database: MS SQL Server
 sql help please
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

philsbbs
Junior Member

United Kingdom
397 Posts

Posted - 12 September 2007 :  20:14:47  Show Profile
The following code works :-

'## Forum_SQL - Find all records with the search criteria in them
strmembernm = Request.QueryString("mem")
strSql = "SELECT " &strTablePrefix & "PM.M_FROM, " &strTablePrefix & "PM.M_ID, " &strTablePrefix & "PM.M_SUBJECT, "&strTablePrefix & "PM.M_TO, " &strTablePrefix & "PM.M_SENT "
strSql = strSql & " FROM " &strTablePrefix & "PM "
strSql = strSql & " ORDER BY " & strTablePrefix & "PM.M_FROM ASC"

but i like the PM_FROM and the PM_TO to give the members name from the members table instead of the members i.d, can you please help.

Phil

gary b
Junior Member

USA
267 Posts

Posted - 12 September 2007 :  23:04:39  Show Profile  Visit gary b's Homepage
quote:
Originally posted by philsbbs

The following code works :-

'## Forum_SQL - Find all records with the search criteria in them
strmembernm = Request.QueryString("mem")
strSql = "SELECT " &strTablePrefix & "PM.M_FROM, " &strTablePrefix & "PM.M_ID, " &strTablePrefix & "PM.M_SUBJECT, "&strTablePrefix & "PM.M_TO, " &strTablePrefix & "PM.M_SENT "
strSql = strSql & " FROM " &strTablePrefix & "PM "
strSql = strSql & " ORDER BY " & strTablePrefix & "PM.M_FROM ASC"

but i like the PM_FROM and the PM_TO to give the members name from the members table instead of the members i.d, can you please help.



Have you tried this:
strmembernm = Request.QueryString("mem")
strSql = "SELECT " &strTablePrefix & "PM.M_FROM, " &strTablePrefix & "PM.M_FirstName, " &strTablePrefix & "PM.M_LastName, " &strTablePrefix & "PM.M_SUBJECT, "&strTablePrefix & "PM.M_TO, " &strTablePrefix & "PM.M_SENT "
strSql = strSql & " FROM " &strTablePrefix & "PM "
strSql = strSql & " ORDER BY " & strTablePrefix & "PM.M_FROM ASC"

I do not know the field names. Replace FirstName and LastName with correct field names.

Assuming the amended query works, is the page configured to display the new fields (data) returned by the query?


Go to Top of Page

philsbbs
Junior Member

United Kingdom
397 Posts

Posted - 14 September 2007 :  15:14:29  Show Profile
This relates to private messaging and there is no firstname and lastname fields on ly the FROM and TO fields which are the same as the members i.d in the members table.

Phil
Go to Top of Page

balexandre
Junior Member

Denmark
418 Posts

Posted - 15 September 2007 :  13:32:47  Show Profile  Visit balexandre's Homepage
so, just use 2 INNER JOIN (if you are using Access or MS SQL)

I don't know the tables or names, but here I give you what you need to have:


SELECT
 UserFrom.FirstName + ' ' + UserFrom.LastName,
 UserTo.FirstName + ' ' + UserTo.LastName,
 PM.M_Subject, PM.M_Sent
FROM
 PM
 INNER JOIN UserTable UserFrom ON PM.M_FROM = UserFrom.UserID
 INNER JOIN UserTable UserTo ON PM.M_TO = UserTo.UserID
ORDER BY 
 UserFrom.FirstName + ' ' + UserFrom.LastName ASC;


so, you are selecting your PM table and 2 times the user table, one for the FROM and one for the TO
the inner join will act as a glue between the UserID in the User Table and the ID in the PM table



easy right?

Bruno Alexandre
(Strøby, DANMARK)

"a Portuguese in Danmark"



Edited by - balexandre on 15 September 2007 13:33:40
Go to Top of Page

philsbbs
Junior Member

United Kingdom
397 Posts

Posted - 15 September 2007 :  15:51:10  Show Profile
from the pm table
=
strSql = "SELECT " &strTablePrefix & "PM.M_FROM, " &strTablePrefix & "PM.M_ID, " &strTablePrefix & "PM.M_SUBJECT, "&strTablePrefix & "PM.M_TO, " &strTablePrefix &
=
i need M_FROM to join to M_USERNAME in the members table
and also M_TO to join to M_USERNAME in the members table.

hope this makes sense.

Phil
Go to Top of Page

philsbbs
Junior Member

United Kingdom
397 Posts

Posted - 16 September 2007 :  09:00:17  Show Profile
i've done this if anyone else has private messages mod installed and wants a copy, feel free to email me.

Phil
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 3.91 seconds. Powered By: Snitz Forums 2000 Version 3.4.07