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 2008 Forums
 Transact-SQL (2008)
 select query usign if condition with a join

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2011-04-12 : 15:59:58
is it possible to use the following If condition which has a join with the below Select query, this select is part of my SP:


If @resultSet < 1
Begin
FROM TAB_ccsNetDM AS A
End

Else
Begin
FROM #result_set inner join TAB_DM AS A on #result_set.dmid=A.DMID
End


SET @SQL = 'SELECT DISTINCT A.ProgID,' + @SQLField + 'F.Contractno,A.ProjID, A.ContractID, A.DMNo, A.DMTypeID, A.DMID,
A.Agency, A.DMTitle, A.Deleted
FROM #result_set inner join TAB_DM AS A on #result_set.dmid=A.DMID
JOIN TAB_UserAccess AS B ON (A.ProgID = B.ProgID AND A.ProjID = B.ProjID AND A.ContractID = B.ContractID)
Left Outer Join TAB_Contracts F ON A.ContractID = F.ContractID ' + @SQLJOIN


Thank you very much for the helpful info.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-12 : 16:29:54
You can't do it like that, but you can by building @SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -