Home » SQL & PL/SQL » SQL & PL/SQL » Case When statement in Insert statement
Case When statement in Insert statement [message #423537] Fri, 25 September 2009 03:32 Go to next message
GuestUser32
Messages: 26
Registered: August 2009
Junior Member
HI

I have an INSERT statement and inside this I need to write an if statement to check some values.
Below is sort of what I want to do, is that possible?

thanks

INSERT INTO TABLE (COLUMN1)
VALUES
(  case
  WHEN table.column= 'something' THEN 'something' 
  ELSE 'something'
  end
)
Re: Case When statement in Insert statement [message #423538 is a reply to message #423537] Fri, 25 September 2009 03:45 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
It is possible if you're doing an INSERT INTO...SELECT statement, but in an INSERT...VALUES, you don't have a table.column to refer to (unless you're doing this in Pl/Sql)
Re: Case When statement in Insert statement [message #423542 is a reply to message #423538] Fri, 25 September 2009 04:37 Go to previous messageGo to next message
GuestUser32
Messages: 26
Registered: August 2009
Junior Member
Thanks for the reply.
I have got another problem after solving the one in the subject header.
Basically I have a trigger that fires when a field in Table1 is updated. When this table is updated some values are inserted into Table2. This is simple.
However the problem comes because in my INSERT statement into Table2 I need to check some values in Table1 hence why I needed the case statement in the Insert statement.
This causes a mutating error to appear.
Is there a way around this? I need to check the values in Table1 in the trigger.
thanks
just ask if this doesnt make sense and I will try and explain it again!
Re: Case When statement in Insert statement [message #423545 is a reply to message #423542] Fri, 25 September 2009 04:49 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
New question new topic.
This one is closed.

forum guide, posting guidelines
If you found an answer yourself, post it. That way we know the issue is resolved and we might learn from it.

Please read and follow it.

Regards
Michel
Re: Case When statement in Insert statement [message #423546 is a reply to message #423545] Fri, 25 September 2009 04:50 Go to previous messageGo to next message
GuestUser32
Messages: 26
Registered: August 2009
Junior Member
Solved. Used answer given above.

thanks
Re: Case When statement in Insert statement [message #423560 is a reply to message #423546] Fri, 25 September 2009 05:39 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And in details it is?

Regards
Michel
Previous Topic: Mutating Trigger Error
Next Topic: Data Dictionary
Goto Forum:
  


Current Time: Sat Dec 03 18:03:44 CST 2016

Total time taken to generate the page: 0.14725 seconds