Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Inserting using Case Statement
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 04/16/2002 :  10:04:58  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Manish Garg writes "i want to insert a record to a different table depending on the variable passed as argument using case statement."

Page47
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 04/16/2002 :  11:17:42  Show Profile  Reply with Quote
Not possible (sort-of).

An INSERT statement can only insert rows into one table or view. A case statement does evaluate a list of conditions and return one of multiple possible results expressions, however, it is not allowed as part of the table_name arguement.

You need to either use IF...ELSE to test your variable for a certain condition and then use the flow control to execute the proper insert statement ... or ...

(Here is the sort-of part). If you are on SQL 2k, you can create an an instead of trigger on a view or table to route the insert to the correct base tables. In SQL 7, and updatable view can modify more than one table involved in the view, as long as SQL Server can translate the update request unambiguously to update in the base tables referenced in the view definition. I've never done that in SQL 7 for an insert and I'm not sure its possible...

<O>

Edited by - Page47 on 04/16/2002 11:20:17
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000