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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Outer Join in SQL Server

Author  Topic 

bhushanhegde
Starting Member

14 Posts

Posted - 2008-11-27 : 01:07:13
Hi,
Following is a one outer join query which runs in oracle.
But it gives syntax error in sql server.
pls help me to change the following query to sql and I need same output.
Query is as follows:


SELECT a.profilemaster_pkey,a.groupname,a.profile_name,b.val,CASE WHEN a.profile_mode='I' THEN 'INSERT' WHEN a.profile_mode='U' THEN 'UPDATE/INSERT' WHEN a.profile_mode='D'THEN 'DOWNLOAD' END "Profile Mode"
FROM (SELECT m.profilemaster_pkey ,G.GROUPNAME, m.profile_name,m.profile_mode FROM
FM_PROFILEMAST m,fm_profilegroup G
WHERE G.GROUPID=m.groupid) a,
(SELECT m.profilemaster_pkey , c.val val FROM fm_ldr_syntx_dtls dts,fm_profile_cfile c,
FM_PROFILEMAST m WHERE dts.parm_stmt_syntx='INFILE ' AND dts.syntx_dtls_pkey=c.ldr_syntx_dtls_pkey
AND c.profilemaster_pkey =m.profilemaster_pkey) b
WHERE a.profilemaster_pkey = b.profilemaster_pkey(+)
order by upper(a.groupname);

Regards
bhushan

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-11-27 : 01:10:39
try this
SELECT  a.profilemaster_pkey,
a.groupname ,
a.profile_name ,
b.val ,
CASE
WHEN a.profile_mode='I'
THEN 'INSERT'
WHEN a.profile_mode='U'
THEN 'UPDATE/INSERT'
WHEN a.profile_mode='D'
THEN 'DOWNLOAD'
END "Profile Mode"
FROM
(SELECT m.profilemaster_pkey ,
G.GROUPNAME ,
m.profile_name ,
m.profile_mode
FROM FM_PROFILEMAST m
INNER JOIN fm_profilegroup G ON G.GROUPID=m.groupid
) a
RIGHT OUTER JOIN
(SELECT m.profilemaster_pkey ,
c.val val
FROM fm_ldr_syntx_dtls dts
INNER JOIN fm_profile_cfile c ON dts.syntx_dtls_pkey = c.ldr_syntx_dtls_pkey
INNER JOIN FM_PROFILEMAST m ON c.profilemaster_pkey = m.profilemaster_pkey
WHERE dts.parm_stmt_syntx = 'INFILE '
) b
ON a.profilemaster_pkey = b.profilemaster_pkey
ORDER BY upper(a.groupname);


"There is only one difference between a dream and an aim.
A dream requires soundless sleep to see,
whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page

bhushanhegde
Starting Member

14 Posts

Posted - 2008-11-27 : 03:58:27
Hi Peter,
Ur query has slite difference.
From my query output is 53 rows.
but from ur query output is only 49 rows.

pls check
Go to Top of Page

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-11-27 : 04:27:25
what is = col(+) in Oracle? is it left or right join,
change the join accordingly.
Without some sample data how can i check the noof records?

"There is only one difference between a dream and an aim.
A dream requires soundless sleep to see,
whereas an aim requires sleepless efforts to achieve..!!"
Go to Top of Page

bhushanhegde
Starting Member

14 Posts

Posted - 2008-11-27 : 05:16:58
Hi,
yes u r correct...
its LEFT.
Actually you put RIGHT...

Thank you...
Go to Top of Page
   

- Advertisement -