Re: Reaching columns -in C#.net- in queries with multiple tables with the same column name
From: Jeff Papiez [MS] (jpapiezonline_at_microsoft.com)
Date: 02/16/04
- Next message: David Browne: "Re: tricky ado.net question"
- Previous message: William Ryan eMVP: "Re: Access Database Edit"
- In reply to: Ed-it: "Reaching columns -in C#.net- in queries with multiple tables with the same column name"
- Next in thread: Eddie Baby: "Re: Reaching columns -in C#.net- in queries with multiple tables with the same column name"
- Reply: Eddie Baby: "Re: Reaching columns -in C#.net- in queries with multiple tables with the same column name"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 16 Feb 2004 12:42:06 -0800
You can give new names to your colums and reference them without a hitch..
for example, you could re-write your query like this:
SELECT a.id AS AId, b.id AS BId
FROM a
INNER JOIN b ON a.id = b.id
The "AS" is optional, though it helps me with readability.
--
Jeff Papiez, MCSD
SQL Server Integration Test Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ed-it" <ed-it@euronet.nl> wrote in message
news:6d7b9e63.0402160949.142741af@posting.google.com...
> Hello,
>
> I'm migrating my C#.net application from a MS Access-database to SQL
> Server 2000. Now I found a problem.
>
> In my code I use a lot (and I mean a lot) of queries with multiple
> tables and some tables have columns with the same names ("id", "name"
> etc). For example:
>
> SELECT a.id, b.id FROM a INNER JOIN b ON a.id=b.id
> or
> SELECT a.id, b.id FROM a, b
>
> In MS Access I can use the column names "a.id" and "b.id" (e.g. in
> reports or datagrids). Now in SQL Server I see that there will be 2
> columns named "id", there is no distinction, so no "a.id" and "b.id".
> I see it also in the Query Analyzer. So my datagrids and reports and
> sourcecode can't find the right column anymore, they are mapped to
> "a.id" and "b.id". I found out that I can use aliasses (SELECT a.id as
> 'a.id', b.id as 'b.id' FROM...), but is there another way, so that I
> don't have to change every query, and even worse, my datagrids and
> reports?
>
> Thanks in advance,
> Ed
- Next message: David Browne: "Re: tricky ado.net question"
- Previous message: William Ryan eMVP: "Re: Access Database Edit"
- In reply to: Ed-it: "Reaching columns -in C#.net- in queries with multiple tables with the same column name"
- Next in thread: Eddie Baby: "Re: Reaching columns -in C#.net- in queries with multiple tables with the same column name"
- Reply: Eddie Baby: "Re: Reaching columns -in C#.net- in queries with multiple tables with the same column name"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|