Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Can i join a table based on If Condition

$
0
0
select * from 
abc a
join( if @param=1
    begin
		SELECT 
		distinct [Act_ID]   
		FROM [Asses]
		where [tobacco]=1
	end
	if @param=2
	begin
			SELECT 
			distinct  [Act_ID]   
			FROM [Asses]
			where bariatricsupport=1
	end
	if @param=3
	begin
				SELECT 
				distinct [Act_ID]   
				FROM [Asses]
				where bariatricsurgery=1
	end
	if @param=4
	begin
				SELECT 
				distinct [Act_ID]   
				FROM [Asses]
				where stress=1
	end
	if @param=5
	begin
		SELECT 
		distinct [Act_ID]   
		FROM [Asses]
		where weight=1
    	end 
    	)C on a.Act_ID=c.Act_ID 
Please let me know if this is possible if not is there any approach better suits my scenario?

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>