Ask a Question related to ASP Database, Design and Development.
-
Mikael Hellström #1
syntax problem
hi!!
This is my problem. Im planing this without success
*i have 3 tables table1 table2 and table3...
*The tables have some fields with the same name for example
both table 2 and table 3 have the field "age"
*The field id is a key
select * from a table1, b table2, c table3 where a.id=session("memberId")
and b.id= session("memberId") and c.id=session("memberId")
MY QUESTION ARE
How do i get data from tables that have the same field name like the example
table 2 and table 3???
My guess are something like this:
response.write recordsset(b.age) and for the other
response.write recordset(c.age)..
This is wrong syntax i know, but how do i write the syntax in asp?
Mikael Hellström Guest
-
<cfquery> syntax problem
Guys can someone tell me whats wrong with the line I have put in bold? Im trying to run this query but I get an error telling me the syntax is wrong... -
INSERT MAX(ID) Syntax problem
Trying to get the ID (autonumber) of a record that has just been inserted and insert it into a different table but I either get a syntax error or a... -
Syntax Coloring Problem with Xemacs
hello I have Xemacs 21.4 and Ruby 1.8.0 whenever I type $' in my Ruby code Xemacs treats the following Code as string and everything is green.... -
IE problem with -> syntax
Hello, My environment is win2k, apache2, php 4 something. My browser is IE. My example is this. $a = new LinkName(); $b =... -
Syntax error problem
The following is the source of a a function I am trying to define in Informix IDS 9.3 (Windows 2000 Server). As far as I can figure, the syntax... -
Bob Barrows #2
Re: syntax problem
Replies inline:
Mikael Hellström wrote:Why do your table aliases come before the table names here? This looks like>
> *i have 3 tables table1 table2 and table3...
> *The tables have some fields with the same name for example
> both table 2 and table 3 have the field "age"
> *The field id is a key
>
> select * from a table1, b table2, c table3 where
an invalid query. What is your database?
Unless you are deliberately doing a cross-join (cartesian product), your> a.id=session("memberId") and b.id= session("memberId") and
> c.id=session("memberId")
>
example query here does not seem to be correct. You should be relating the
tables to each other. Depending on what your database is, you should be
using the ANSI standard syntax (assuming id is a numeric column):
" ... from table1 a INNER JOIN table2 b
ON a.id=b.id INNER JOIN table3 c ON a.id=c.id
WHERE a.id=" & session("memberId")
This is yet another reason to avoid using "select *" (SelStar) in production> MY QUESTION ARE
> How do i get data from tables that have the same field name like the
> example table 2 and table 3???
> My guess are something like this:
>
> response.write recordsset(b.age) and for the other
> response.write recordset(c.age)..
>
> This is wrong syntax i know, but how do i write the syntax in asp?
code. You should always explicitly list the columns you want your query to
return. In this case, it will allow you to use column aliases to
differentiate the like-named columns from each table. Like this (use your
own nomenclature - "AgeFrom_" is merely for the sake of the example):
Select a.id, a.col1,b.age As AgeFromB, c.age As AgeFromC ...
Then, after you open the recordset, you can use the column alias to specify
the specific age you wish to read:
response.write recordset("AgeFromB")
Avoiding SelStar will also help you avoid retrieving unnecessary data. For
example, why retrieve the id column from tables 2 and 3? You know they are
going to contain the same data as the id column in table 1: why retrieve
unnecessary data and cause extra network traffic and unnecessary use of
resources?
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows Guest
-
Lee Mundie #3
Syntax Problem
Hi,
Im trying to get his SQl to work but run thru a query analiser tells me
there is a syntax error and in the browser returns no results - any ideas?
SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERE bl.Author_ID
= @LoggedInUserID AND bl.Buddy_ID <> 2
ORDER BY m.Username ASC;
It worked before modification from:
SELECT tblBuddyList.*, Members.Username, Members.Author_ID
FROM Members INNER JOIN tblBuddyList ON Members.Author_ID
= tblBuddyList.Buddy_ID WHERE tblBuddyList.Author_ID=" & lngLoggedInUserID &
"
AND tblBuddyList.Buddy_ID <> 2
ORDER BY Members.Username ASC;
Thanks in advance
Lee
Lee Mundie Guest
-
Aaron Bertrand [MVP] #4
Re: Syntax Problem
What is the EXACT error message (there are different kinds of syntax errors;
VBScript or from the database)? What is the EXACT code you are using? What
database and version are you using? Are you connecting via ODBC or OLEDB?
<followups set to asp.db only>
--
Aaron Bertrand
SQL Server MVP
[url]http://www.aspfaq.com/[/url]
"Lee Mundie" <lee.j.mundie@ntlworld.com> wrote in message
news:0GJvb.1965$B03.1220806@newsfep2-win.server.ntli.net...me> Hi,
> Im trying to get his SQl to work but run thru a query analiser tellsbl.Author_ID> there is a syntax error and in the browser returns no results - any ideas?
>
> SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
> FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
> LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERE&> = @LoggedInUserID AND bl.Buddy_ID <> 2
> ORDER BY m.Username ASC;
>
> It worked before modification from:
>
> SELECT tblBuddyList.*, Members.Username, Members.Author_ID
> FROM Members INNER JOIN tblBuddyList ON Members.Author_ID
> = tblBuddyList.Buddy_ID WHERE tblBuddyList.Author_ID=" & lngLoggedInUserID> "
> AND tblBuddyList.Buddy_ID <> 2
> ORDER BY Members.Username ASC;
>
> Thanks in advance
>
> Lee
>
>
Aaron Bertrand [MVP] Guest
-
Bob Barrows #5
Re: Syntax Problem
I was going to ask if this was Access or SQL Server, but "@LoggedInUserID"
leads me to lean more towards SQL Server. Please don't make us guess. :-)
The version of SQL Server may also be relevant.
Lee Mundie wrote:m.Username,> Hi,
> Im trying to get his SQl to work but run thru a query analiser
> tells me there is a syntax error and in the browser returns no
> results - any ideas?
>
> SELECT
m.Author_ID,
au.Author_ID AS ActiveUserAuthorIDINNER JOIN Members m ON bl.Buddy_ID = m.Author_ID> FROM tblBuddyList blWHERE> LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_IDAND bl.Buddy_ID <> 2> bl.Author_ID = @LoggedInUserIDHmm, so I'm assuming this is from a stored procedure? When you try to run it> ORDER BY m.Username ASC;
in Query Analyzer, do you declare the @LoggedInUserID variable and give it a
value?
So I'm correctly assuming you're rewriting this to get away from dynamic>
> It worked before modification from:
>
> SELECT tblBuddyList.*, Members.Username, Members.Author_ID
> FROM Members INNER JOIN tblBuddyList ON Members.Author_ID
> = tblBuddyList.Buddy_ID WHERE tblBuddyList.Author_ID=" &
> lngLoggedInUserID & "
> AND tblBuddyList.Buddy_ID <> 2
> ORDER BY Members.Username ASC;
sql? Good!
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows Guest
-
Lee Mundie #6
Re: Syntax Problem
Hi,
It appears to be a VBScript Error syntax, at the INNER JOIN - using ASP,
Access DB via ODBC on JET4. The final intention is to SQL the DB, but find
it easier in initial stages to dev on Access.
Still kinda getting there with ASP, so forgive if vague or stoopid
somethimes!!!
This is the exact code:
SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERE bl.Author_ID
= @LoggedInUserI AND bl.Buddy_ID <> 2
ORDER BY m.Username ASC;
Thanks in Advance
Lee
Lee Mundie Guest
-
Bob Barrows #7
Re: Syntax Problem
Lee Mundie wrote:
Very good idea. Even better if you save the query in Access and run the> Hi,
> It appears to be a VBScript Error syntax, at the INNER JOIN - using
> ASP, Access DB via ODBC on JET4. The final intention is to SQL the
> DB, but find it easier in initial stages to dev on Access.
saved query from ASP. I've posted many examples of vbscript code to run
saved parameter queries in Access - a quick Google seach should easily turn
them up.
Excuse me, but how can Author_ID, presumably a Number field, ever be equal>
> Still kinda getting there with ASP, so forgive if vague or stoopid
> somethimes!!!
>
> This is the exact code:
>
> SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
> FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
> LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERE
> bl.Author_ID = @LoggedInUserI AND bl.Buddy_ID <> 2
> ORDER BY m.Username ASC;
>
> Thanks in Advance
>
> Lee
to @LoggedInUserI, a non-delimited string?
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows Guest
-
Bob Barrows #8
Re: Syntax Problem
Lee Mundie wrote:
OK, you're trying to use @LoggedInUserI as a parameter right? You need to> Hi,
> It appears to be a VBScript Error syntax, at the INNER JOIN - using
> ASP, Access DB via ODBC on JET4. The final intention is to SQL the
> DB, but find it easier in initial stages to dev on Access.
>
> Still kinda getting there with ASP, so forgive if vague or stoopid
> somethimes!!!
>
> This is the exact code:
>
> SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
> FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
> LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERE
> bl.Author_ID = @LoggedInUserI AND bl.Buddy_ID <> 2
> ORDER BY m.Username ASC;
>
surround it with brackets []
Also, Access is very "fussy" about joining more than two tables: it wants
you to group the joins using parentheses. I suggest using GUI Design View to
create your basic query, putting all the tables in and creating all the
joins. Then switch to SQL View to see where Access puts the grouping
parentheses in the FROM clause.
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows Guest
-
Aaron Bertrand [MVP] #9
Re: Syntax Problem
> It appears to be a VBScript Error syntax,
"Appears to be"? Could you COPY & PASTE the error message from the browser?
bl.Author_ID> This is the exact code:
>
> SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
> FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
> LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERENo, that is not ASP code, that is plain text. What I mean by code is the> = @LoggedInUserI AND bl.Buddy_ID <> 2
> ORDER BY m.Username ASC;
ASP code that generates the error.
--
Aaron Bertrand
SQL Server MVP
[url]http://www.aspfaq.com/[/url]
Aaron Bertrand [MVP] Guest
-
Re: Syntax Problem
Lee,
what value do u set to @LoggedInUserID?
"Lee Mundie" <lee.j.mundie@ntlworld.com> wrote in message
news:0GJvb.1965$B03.1220806@newsfep2-win.server.ntli.net...me> Hi,
> Im trying to get his SQl to work but run thru a query analiser tellsbl.Author_ID> there is a syntax error and in the browser returns no results - any ideas?
>
> SELECT m.Username, m.Author_ID, au.Author_ID AS ActiveUserAuthorID
> FROM tblBuddyList bl INNER JOIN Members m ON bl.Buddy_ID = m.Author_ID
> LEFT JOIN tblActiveUser au ON bl.Buddy_ID = au.Author_ID WHERE&> = @LoggedInUserID AND bl.Buddy_ID <> 2
> ORDER BY m.Username ASC;
>
> It worked before modification from:
>
> SELECT tblBuddyList.*, Members.Username, Members.Author_ID
> FROM Members INNER JOIN tblBuddyList ON Members.Author_ID
> = tblBuddyList.Buddy_ID WHERE tblBuddyList.Author_ID=" & lngLoggedInUserID> "
> AND tblBuddyList.Buddy_ID <> 2
> ORDER BY Members.Username ASC;
>
> Thanks in advance
>
> Lee
>
>
Guest
-
John Olav #11
Syntax problem
Okay, I'm a newbie, the following script are commented and explained, but
the something is wrong with the syntax. Anyone, any idea?
<php for login check and redirect of users according to their login details
against data in MySQL>
// connection - custnumber and orgnmmer associated with similar login fields
in the login form, values must be equal to DB-fields
mysql_connect("my.ip.address", "$custnumber", "@orgnummer") or
die(mysql_error());
mysql_select_db("custdatabase") or die(mysql_error());
// select relevant table info
$query "SELECT custnumber,orgnummer,rabkat FROM kunder";
//check to see if login details are equal to those in db and whether
"rabkat" are value 10 or 20, redirect users logged in according to the value
in DB under column "rabkat"
if (custnumber=="$custnumber")
{
orgunmmer=="$orgnummer";
rabkat==10;
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=html-redirect1.html\">";
}
if (custnumber=="$custnumber")
{
orgnummer=="$orgnummer";
rabkat==20;
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=html-redirect2.html\">";
}
else if (custnumber=="$custnumber")
{
orgnummer=="$orgnummer";
rabkat="";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=html-redirect3.html\">";
}
John Olav Guest
-
Brian Wakem #12
Re: Syntax problem
John Olav wrote:
> Okay, I'm a newbie, the following script are commented and explained, but
> the something is wrong with the syntax. Anyone, any idea?
>
> <php for login check and redirect of users according to their login
> details against data in MySQL>
>
> // connection - custnumber and orgnmmer associated with similar login
> fields in the login form, values must be equal to DB-fields
> mysql_connect("my.ip.address", "$custnumber", "@orgnummer") or
> die(mysql_error());
> mysql_select_db("custdatabase") or die(mysql_error());
>
> // select relevant table info
> $query "SELECT custnumber,orgnummer,rabkat FROM kunder";
>
> //check to see if login details are equal to those in db and whether
> "rabkat" are value 10 or 20, redirect users logged in according to the
> value in DB under column "rabkat"
>
> if (custnumber=="$custnumber")
> {
> orgunmmer=="$orgnummer";
> rabkat==10;
> echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;
> URL=html-redirect1.html\">"; }
>
> if (custnumber=="$custnumber")
> {
> orgnummer=="$orgnummer";
> rabkat==20;
> echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;
> URL=html-redirect2.html\">"; }
> else if (custnumber=="$custnumber")
> {
> orgnummer=="$orgnummer";
> rabkat="";
> echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5;
> URL=html-redirect3.html\">"; }
I can't commment on the php, having never touched it, but was is obvious to
me is that you have 3 different spellings of org...
(orgnmmer,orgnummer,orgunmmer). Surely at least 2 of them are wrong.
--
Brian Wakem
Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
Brian Wakem Guest
-
Jerry Stuckle #13
Re: Syntax problem
Hi, John,
Comments interspaced below...
John Olav wrote:This is invalid syntax. You need to call mysql_query to actually do the query, i.e.> Okay, I'm a newbie, the following script are commented and explained, but
> the something is wrong with the syntax. Anyone, any idea?
>
> <php for login check and redirect of users according to their login details
> against data in MySQL>
>
> // connection - custnumber and orgnmmer associated with similar login fields
> in the login form, values must be equal to DB-fields
> mysql_connect("my.ip.address", "$custnumber", "@orgnummer") or
> die(mysql_error());
> mysql_select_db("custdatabase") or die(mysql_error());
>
> // select relevant table info
> $query "SELECT custnumber,orgnummer,rabkat FROM kunder";
>
$query = "SELECT custnumber,orgnummer,rabkat FROM kunder";
$result= mysql_query($query);
You've done the query, but now you must fetch the result:> //check to see if login details are equal to those in db and whether
> "rabkat" are value 10 or 20, redirect users logged in according to the value
> in DB under column "rabkat"
>
$data = mysql_fetch_array($result);
Results of the first matching row will be in $data['custnumber'],
$data['orgnummer'], etc.
if ($data['custnumber'] == $custnumber)> if (custnumber=="$custnumber")
I'm assuming $custnumber is a variable here - so no quotes around it
$orgnummer = $data['orgnummer'];> {
> orgunmmer=="$orgnummer";
Not sure why you're checking this again - it's the same data as before> rabkat==10;
> echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=html-redirect1.html\">";
> }
>
> if (custnumber=="$custnumber")
If you're looking for a specific row, you should use the WHERE clause to fetch> {
> orgnummer=="$orgnummer";
> rabkat==20;
> echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=html-redirect2.html\">";
> }
> else if (custnumber=="$custnumber")
> {
> orgnummer=="$orgnummer";
> rabkat="";
> echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=html-redirect3.html\">";
> }
>
>
that row, i.e.
$query = "SELECT orgnummer,rabkat FROM kunder WHERE custnumber=$custnumber";
Assuming that $custnumber is a numeric value.
Hopefully this will get you started. I'm not sure what you're trying to do, so
I can't comment further on your code structure.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
[email]jstucklex@attglobal.net[/email]
==================
Jerry Stuckle Guest



Reply With Quote

