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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to link on field and sometims on another field

Status
Not open for further replies.

sandeep0000

Programmer
May 10, 2007
98
US
i am doing a report. i have two tables es_sts and INDV_TM_LIM_CLK.

both tables have a cwin field , both are have cwin populated.

that is one link i need to do.

but on the other link, i have cs_id in both tables also.
but sometimes the INDV_TM_LIM_CLK is populated , sometimes it is.

so i want to link on cwin first and then

if my INDV_TM_LIM_CLK ,cs_id is not null then i want that to be my second link. but if the cs_id in INDV_TM_LIM_CLK is null, i only want to link on cwin.

thanks
 
You can specify that within your JOIN.

Code:
select YourColumns
from INDV_TM_LIM_CLK
JOIN es_sts on (INDV_TM_LIM_CLK.csid is null and INDV_TM_LIM_CLK.cwin = es_sts.cwin) or (INDV_TM_LIM_CLK.csid is not null and INDV_TM_LIM_CLK.csis = es_sts.csis)
WHERE ...

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
when INDV_TM_LIM_CLK.csid is not null then i need to link by cwin and csid , what u wrote would do that or should it be like this

select YourColumns
from INDV_TM_LIM_CLK
JOIN es_sts on (INDV_TM_LIM_CLK.csid is null and INDV_TM_LIM_CLK.cwin = es_sts.cwin) or (INDV_TM_LIM_CLK.csid is not null and INDV_TM_LIM_CLK.csis = es_sts.csis
and INDV_TM_LIM_CLK.cwin = es_sts.cwin )
WHERE ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top