Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I created a query and now need to create a temporary table. It will contain the below fields. I thought I remembered how to complete this task but it doesn't run. The Query runs fine if I comment out the "IF" & "INTO" lines.
IF OBJECT_ID ('tempdb..#lstLeft') is not null drop table #lstLeft
SQL
SELECT
       SStaff.StaffName,
       PatientProviders.ProviderRole,
       SPatient.PatientName,
       Immunization.ImmunizationDateTime,
       Team.ServiceSection,
       Immunization.VisitDateTime,
       SPatient.PhoneResidence,
       SPatient.PhoneWork,
       SPatient.DateOfBirth,
       SPatient.Age,
       SPatient.Gender,
       SPatient.PatientSID
  INTO #lstLeft
  FROM /* the table and fields work fine in the query not trying to create a tempdb */
Posted
Updated 14-Dec-11 2:34am
v3
Comments
Amir Mahfoozi 13-Dec-11 13:21pm    
Your question is unclear.
[no name] 14-Dec-11 0:17am    
Please make the question clear
[no name] 14-Dec-11 8:37am    
you mentioned IF keyword but i didn't find IF keyword in your query

1 solution

I encountered the same problem and It was strange for me too.

I solved this problem by renaming the temporary table name to a new one and suddenly it worked !

So try to rename ALL instances of #lstLeft and try again.

Your way of doing it is correct.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900