Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't create a procedure
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00885418
Message ID:
00885444
Views:
10
Hi Kelly,

The T-SQL compiler is confused in this case. The workaround is to create temporary table ouside of IF block.
select * into #temp from tableA where 1=2
IF x=y BEGIN
  INSERT INTO #temp SELECT from tableA where x=y
  ...
END
...
>I am trying to create a procedure with a simple IF statement included. What I want to accomplish is this:
>
>If x=y
> begin
> select * into #temp from tableA where x=y
> ...
> end
>else
> begin
> select * into #temp from tableA where x=z
> ...
> end
>
>When I try to recompile the procedure I recieve the following message:
>
>"There is already an object named '#temp' in the database."
>
>Why is it creating the temporary table when I try to compile the procedure? And/or what can I do to get around this? The subsequent coding of the procedure needs to reference the one temporary table.
>
>Thanks in advance
>Kelly
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform