| 
	
 | 
 Posted by David Portas on 02/14/06 11:25 
Shwetabh wrote: 
> Hi, 
> I have two tables: Code and Color. 
> The create command for them is : 
> 
> create table Color( 
> 	Partnum varchar(10), 
>                 Eng_Color char(10), 
>                 Span_Color char(20), 
>                 Frch_Color char(20), 
> 	CONSTRAINT pkPartnum PRIMARY KEY(Partnum) 
> ) 
> 
> create table Code 
> ( 
> 	Partnum varchar(10), 
> 	Barcode varchar(11), 
> 	I2of5s varchar(13), 
> 	I2of5m varchar(13), 
> 	UPC varchar(11), 
> 	BigboxBCode varchar(11), 
> 	DrumBCode varchar(11), 
> 	TrayBCode varchar(11), 
> 	QtyBCode varchar(11), 
> 	CONSTRAINT fkPartnum FOREIGN KEY(Partnum) references Color(Partnum) 
> ) 
> 
> 
> Now my question is, 
> how can i give a select statement such that I can get all the fields as 
> output. 
> Also plz note that the above is a sample. I have another 9 tables and I 
> need a solution 
> such that on being refered by Partnum, I can get all the attributes. 
> 
> Thanks 
 
I guess you'll want an inner join. You can read about types of joins in 
Books Online. For example: 
 
SELECT 
 D.partnum, D.barcode, D.i2of5s, D.i2of5m, D.upc, D.bigboxbcode, 
 D.drumbcode, D.traybcode, D.qtybcode, 
 C.eng_color, C.span_color, C.frch_color 
 FROM Color AS C 
 JOIN Code AS D 
  ON C.partnum = D.partnum ; 
 
-- 
David Portas, SQL Server MVP 
 
Whenever possible please post enough code to reproduce your problem. 
Including CREATE TABLE and INSERT statements usually helps. 
State what version of SQL Server you are using and specify the content 
of any error messages. 
 
SQL Server Books Online: 
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx 
--
 
  
Navigation:
[Reply to this message] 
 |