aspvbnetnerd
Programmer
I am trying to understand temporary tables that begins with #
With a simple query the creates a query and drops a query. This work Okay.
Tried the same but creating two procedure. One for creating a table and one for dropping a table
The I try to execute the procedure
And I am getting an error that says
Cannot drop the table '#TEMPTABLE, because it does not exist or you do not have permission.
My question is this.
How can I make the second procedure find the #TEMPTABLE?
With a simple query the creates a query and drops a query. This work Okay.
Code:
[COLOR=blue]CREATE[/color] [COLOR=blue]TABLE[/color] [#TEMPTABLE](
[CardboardID] [[COLOR=blue]int[/color]] NOT NULL,
[BuntchID] [[COLOR=blue]int[/color]] [COLOR=blue]IDENTITY[/color](1,1) NOT NULL,
[FirstSerialNumber] [[COLOR=blue]int[/color]] NULL,
[LastSerialNumber] [[COLOR=blue]int[/color]] NULL,
[ScanningDate] [[COLOR=#FF00FF]datetime[/color]] NULL,
[[COLOR=#FF00FF]Year[/color]] [nvarchar](2) NULL,
[DayNumber] [[COLOR=blue]smallint[/color]] NULL,
[ScanningStationID] [[COLOR=blue]smallint[/color]] NULL,
[Created] [[COLOR=#FF00FF]datetime[/color]] NULL [COLOR=blue]DEFAULT[/color] ([COLOR=#FF00FF]GETDATE[/color]()),
[Lost] [[COLOR=blue]bit[/color]] NULL)
[COLOR=blue]DROP[/color] [COLOR=blue]TABLE[/color] #TEMPTABLE
Tried the same but creating two procedure. One for creating a table and one for dropping a table
Code:
[COLOR=blue]CREATE[/color] [COLOR=blue]PROCEDURE[/color] [dbo].[CreateTable]
[COLOR=blue]As[/color]
[COLOR=blue]CREATE[/color] [COLOR=blue]TABLE[/color] [#TEMPTABLE](
[CardboardID] [[COLOR=blue]int[/color]] NOT NULL,
[BuntchID] [[COLOR=blue]int[/color]] [COLOR=blue]IDENTITY[/color](1,1) NOT NULL,
[FirstSerialNumber] [[COLOR=blue]int[/color]] NULL,
[LastSerialNumber] [[COLOR=blue]int[/color]] NULL,
[ScanningDate] [[COLOR=#FF00FF]datetime[/color]] NULL,
[[COLOR=#FF00FF]Year[/color]] [nvarchar](2) NULL,
[DayNumber] [[COLOR=blue]smallint[/color]] NULL,
[ScanningStationID] [[COLOR=blue]smallint[/color]] NULL,
[Created] [[COLOR=#FF00FF]datetime[/color]] NULL [COLOR=blue]DEFAULT[/color] ([COLOR=#FF00FF]GETDATE[/color]()),
[Lost] [[COLOR=blue]bit[/color]] NULL)
Code:
[COLOR=blue]CREATE[/color] [COLOR=blue]PROCEDURE[/color] [dbo].[DropTempTable]
[COLOR=blue]As[/color]
[COLOR=blue]DROP[/color] [COLOR=blue]TABLE[/color] #TEMPTABLE
The I try to execute the procedure
Code:
CreateTable
DropTempTable
Cannot drop the table '#TEMPTABLE, because it does not exist or you do not have permission.
My question is this.
How can I make the second procedure find the #TEMPTABLE?