Hi
In below code on select * from #temp. it is giving above erro
set @query = 'select [BookId] [Book ID],BookTitle [Book],[ComboBookName],[CoreRPL],[Lexile],[NumberOfPages],[SessionPlanStatus],[ClosingStock], ' + @cols + '
INTO #temp from (select [BookID] ,BookTitle,[ComboBookName],[CoreRPL],[Lexile],[NumberOfPages],[SessionPlanStatus],Status,[ClosingStock],StudentName from #finalTable
where (('''+@BookID+'''=''0'' OR [BookId] IN('+ cast(@BookID as varchar(Max))+')))) x pivot
( Max(Status) for StudentName in (' + @cols + ')) piv order by BookTitle';
--print @query
--execute (@query)
select * from #temp
Thanks
Ramco RamcoPosted Apr 29, 2023, 5:05 PM
Hi Rajkiran
in the query u see i have written #temp. It should exist
Thanks
Rajkiran SwainPosted Apr 29, 2023, 3:49 PM
The error "Invalid Object Name #temp" usually occurs when the temporary table "#temp" does not exist or has been dropped before it is being accessed.
You can try adding a check before selecting from the temporary table to make sure it exists. For example, you can modify the code like this:
```
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
BEGIN
SELECT * FROM #temp
END
```
This will check if the temporary table "#temp" exists in the current session, and only select from it if it exists.