Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 1st question

Author  Topic 

eject
Starting Member

2 Posts

Posted - 2006-11-29 : 23:21:34
Hi, i'm newbie to sql..
my first project is to create a record which will call information from 2 tables? but some info must refer to other table to get the value.

Here is the code

SELECT HREMPN, F02EPNAM, SHIFT, HRSECT, HRLOCTNO, F03EPNAM1, F03EPNAM2
FROM dbo.TIMS

but HRLOCTNO must refer to other table named dbo.HRTAB where in HRTAB got 2 fields = HRNO, HRCODE

HRLOCTNO from TIMS will may contain same value in HRNO from HRLOCTAB

i want to retrive the HRCODE value from HRTAB where the HRNO contain same value as HRLOCTNO from TIMS.(HRNO=HRLOCTNO)

the result would be like this..
HREMPN, F02EPNAM, SHIFT, HRSECT, HRCODE, F03EPNAM1, F03EPNAM2

can someone please help to solve my 1st problem..

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-30 : 00:09:48
Yes. Read about INNER JOIN and LEFT JOIN in Books Online.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-30 : 00:33:53
SELECT a.HREMPN, a.F02EPNAM, a.SHIFT, a.HRSECT, b.HRCODE, a.F03EPNAM1, a.F03EPNAM2
FROM dbo.TIMS a
LEFT JOIN dbo.HRLOCTAB b ON b.HRNO = a.HRLOCTNO


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

eject
Starting Member

2 Posts

Posted - 2006-11-30 : 01:17:18
Thanks Peso..really apprieciate dat..:)
Go to Top of Page
   

- Advertisement -