| |

VerySource

 Forgot password?
 Register
Search
View: 1082|Reply: 7

A strange error

[Copy link]

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-11 09:30:01
| Show all posts |Read mode
declare @isWastage bit
declare @partcode varchar(20)

set @isWastage=1
set @PartCode='1234567890'

if @isWastage=1 --Requires the calculation result to include loss
   select fpartcode, dosage INTO #TMP2 from tbom007d where fparentpartcode = @PartCode
else
   select fpartcode, dosage*2 INTO #TMP2 from tbom007d where fparentpartcode = @PartCode --This line is wrong

The following error occurred:
Server: Message 2714, Level 16, State 1, Line 11
An object named'#TMP2' already exists in the database.

what happened? Thank you
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-11-11 09:45:01
| Show all posts
declare @isWastage bit
declare @partcode varchar(20)

set @isWastage=1
set @PartCode='1234567890'

if @isWastage=1 --Requires the calculation result to include loss
   select fpartcode, dosage INTO #TMP1 from tbom007d where fparentpartcode = @PartCode
else
   select fpartcode, dosage*2 INTO #TMP2 from tbom007d where fparentpartcode = @PartCode
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-11-11 11:30:01
| Show all posts
TO:我是杀人狂‵My ɡīr!.ˊI miss youˋ. (*^_^*)

  The purpose of the program is to insert different query results into a new table #TMP2 according to whether @isWastage is true.

  When @isWastage is true, I don't know why the statement behind the else is also executed
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-11-11 11:45:02
| Show all posts
Add a judgment in front, if #TMP2 exists, just DROP it. . .
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

 Author| Post time: 2020-11-11 12:00:01
| Show all posts
I added a drop table #TMP2  in the first line, the result is the same, it doesn’t matter whether it is added or not
Reply

Use magic Report

0

Threads

28

Posts

25.00

Credits

Newbie

Rank: 1

Credits
25.00

 China

Post time: 2020-11-11 12:15:01
| Show all posts
declare @isWastage bit
declare @partcode varchar(20)

set @isWastage=1
set @PartCode='1234567890'

if @isWastage=1 --Requires the calculation result to include loss
   begin
   if object_id(N'Tempdb..#TMP2') is not null dorp table #tmp2
   select fpartcode, dosage INTO #TMP2 from tbom007d where fparentpartcode = @PartCode
end
else
begin
   if object_id(N'Tempdb..#TMP2') is not null dorp table #tmp2

   select fpartcode, dosage*2 INTO #TMP2 from tbom007d where fparentpartcode = @PartCode
end - error on this line
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-11-11 12:45:01
| Show all posts
if @isWastage=1
   insert into #tmp2 select fpartcode, dosage from tbom007d where fparentpartcode = @PartCode
else
   insert into #tmp2 select fpartcode, dosage*2 from tbom007d where fparentpartcode = @PartCode
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2020-11-11 13:15:01
| Show all posts
Why is there an if conditional judgment, and the program still fails if the statement after the else is not executed?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list