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

Putting the results of an IF and ELSE in a temp table

$
0
0
Hello all.

Im having an issue with a task. I want to write values into a temp table from an if and else condition.

However in to into #temptable clause of the else it is saying that the table already exist...but it kinda doesnt exist since either the if or else will run.
Here is the code. basically i want to enter in file2 where the date is more that @mdate_s or when it is less.

Thank u
IF @mdate_s < (SELECT MAX(date) from dbo.activity where id=@id)
BEGIN
SELECT  
	activity.*,
	members.*,
	INTO rep.#mFile2
	FROM dbo.activity INNER JOIN dbo.members
	ON activity.id=members.id
	WHERE 	members.id=@id
    AND trans='P'
    AND code='MEO'
END  
ELSE 
BEGIN
SELECT  
	activity.*,
	members.*,
	INTO rep.#mFile2
	FROM dbo.activity INNER JOIN dbo.members
	ON activity.id=members.id
	WHERE 	members.id=@id
    AND trans='P'
    AND code='MEO'

END  


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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