473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Left Join variable not valid

Sfj
Hello folks,

Old programmer learning new tricks.

I think similar issues have been posted, but I would like to ask some help
with the following code...

select [t1.*],[t2.userid] as [userid2],[t2.approved],[t2.type]
from [tblMembers] as t1 left outer join [tblProfiles] as t2
on [t1.userid]=[t2.userid]
where ...

I get the following error...

[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name
't1.userid'.

....but there is a [userid] in both tables. Do I have to make them keys or
something? And I need to do work (add and update) on both tables after the
values are returned.

Also, how bad is my syntax? If you could give advice on removing extraneous
brackets and I would like to not have to use the "as" clause. I really just
want to keep it simple. Whatever works though.

Thanks
Jun 18 '06 #1
3 1652
> select [t1.*],[t2.userid] as [userid2],[t2.approved],[t2.type]
from [tblMembers] as t1 left outer join [tblProfiles] as t2
on [t1.userid]=[t2.userid]
The main problem here is that you are enclosing both the table alias and
column name. Try:

SELECT
[t1].*,
[t2].[userid] AS [userid2],
[t2].[approved],
[t2].[type]
FROM [tblMembers] AS [t1]
LEFT OUTER JOIN [tblProfiles] AS [t2]
ON [t1].[userid] = [t2].[userid]
--
Hope this helps.

Dan Guzman
SQL Server MVP

"Sfj" <sh*******@yahoo.com> wrote in message
news:6h2lg.112415$Ce1.107196@dukeread01... Hello folks,

Old programmer learning new tricks.

I think similar issues have been posted, but I would like to ask some help
with the following code...

select [t1.*],[t2.userid] as [userid2],[t2.approved],[t2.type]
from [tblMembers] as t1 left outer join [tblProfiles] as t2
on [t1.userid]=[t2.userid]
where ...

I get the following error...

[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name
't1.userid'.

...but there is a [userid] in both tables. Do I have to make them keys or
something? And I need to do work (add and update) on both tables after
the values are returned.

Also, how bad is my syntax? If you could give advice on removing
extraneous brackets and I would like to not have to use the "as" clause.
I really just want to keep it simple. Whatever works though.

Thanks

Jun 18 '06 #2
On Sat, 17 Jun 2006 20:47:20 -0500, Sfj wrote:

(snip)
Also, how bad is my syntax? If you could give advice on removing extraneous
brackets
Hi Sfj,

Removing brackets is a great idea - IMO, they only make the query
unreadable. You only really need to enclose a table name, column name,
or other identifier with either brackets (the MS standard that works
across SQL Server and Access, but not outisde the MS world) or double
quotes (the ANSI SQL standard) if it doesn't follow the rules for
identifiers as laid down in Books Online. Most common reasons for
needing brackets or double quotes are: identifiers with embedded spaces,
using reserved words as identifier, using special characters in
identifier or starting identifier with numeric.

If you stick to the rules for identifier names, you'll never need to
delimit them at all.
and I would like to not have to use the "as" clause. I really just
want to keep it simple. Whatever works though.


Though the AS is optional, I recommend always sticking it in. It's just
three extra keystrokes, and it makes your query lots easier to read.

--
Hugo Kornelis, SQL Server MVP
Jun 18 '06 #3
Thank you, gentlemen.

Your answers helped me to resolve and move on.

Jun 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
14
by: Ryan | last post by:
I want to do the following SQL statement in Access. However, it won't allow me to have the secondary part of my join statement and tells me that this is not supported. OK, so Access doesn't support...
9
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to...
6
by: Avaenuha | last post by:
I need to use a left outer join to get all of one table, and match it to specific instances of another table. Eg, report all of A, and where A has made a specific kind of B, report the name of that...
5
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN...
1
by: naveenchhibber | last post by:
Hi all pls tell me that the following statment is valid in oracle 9i or 10g.. update ws set received_by_facility = coalesce(rbf_ouk.organizational_unit_id, 0), ...
0
by: Scotsman | last post by:
Hi All I have a sticky problem! Its a LEFT JOIN sql statement which works fine in MySQL but not when called in Perl. Any ideas? I have 2 tables: campaigns & companies. I'm trying to join them...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.