Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statement!

Status
Not open for further replies.

johnvai

IS-IT--Management
Oct 4, 2003
127
LB
Dear Friends:

I have 2 tables having the following fields:

Stations Printers
---------------- -------------------
Statnum 1 | 2 ID 1 | 2 | 3
Printer1 1 | 0 Type 56| 43| 12
Printer2 2 | 1 Port 2 | 1 | 2

I want with one SQL statement to output the following:

Statnum Printer1 Type1 Port1 Printer2 Type2 Port2
--------------------------------------------------------
1 | 1 | 56 | 2 | 2 | 43 | 1
2 | | | | 1 | 56 | 2

I want the output of one statnum in one row.

Any Suggestions?
 

Select A.Statnum As Statnum ,
Case When A.Printer1 = 0 then Null Else A.Printer1 End As Printer1 ,
'Type1' = ( Select Type from Printers B Where B.ID = A.Printer1 ) ,
'Port1' = ( Select Port from Printers B Where B.ID = A.Printer1 ) ,
Case When A.Printer2 = 0 then Null Else A.Printer2 End ,
'Type2' = ( Select Type from Printers B Where B.ID = A.Printer2 ) ,
'Port2' = ( Select Port from Printers B Where B.ID = A.Printer2 )
From Stations A


Hope This Helps

Regards
Parchure Nikhil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top