dbTalk Databases Forums  

Specifying table names

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss Specifying table names in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
James
 
Posts: n/a

Default Specifying table names - 10-16-2003 , 02:10 PM






I have a database containing several tables, two of the
tables have an identical column I need to use, in Access I
simply prefix the table name before the sql query,

For example
Tables![TStock]![StockCode]=Tables![TOldStock]![Stockcode]

how do I do this in sql server 7 in a Select query.

IE: Select from blah blah blah....

Thanks to anyone who can help with what must be a simple
questions.

Reply With Quote
  #2  
Old   
Vishal Parkar
 
Posts: n/a

Default Re: Specifying table names - 10-16-2003 , 02:59 PM






James,
you can prefix column name with the table name if you have identical columns
in the 2 different table
that you are using in query.
See following example on northwind database on SQL Server.

use northwind
go
select a.customerid, b.customerid
from customers a join orders b
on a.customerid = b.customerid

--The above query is as good as

select a.customerid, b.customerid
from customers a ,orders b
where a.customerid = b.customerid

Just remember you will have to prefix the column name with the required
table name alias or table name.
(But if you are using alias for the tables then you will have to prefix
column names with alias only and not table name)
In above examples im using alias for the tables you, can replace alias with
the table names as well. Which will
turn above query as

select customers.customerid, orders.customerid
from customers ,orders
where customers.customerid = orders.customerid

Search in Books online for following topic which will answer almost all of
your questions.

"SELECT Examples"


--
-Vishal



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.