---
title: "How to select a table from many table while inserting"  
description: "How to select a table from many table while inserting"  
author: "ranjunath govind"  
published: 2014-07-21  
updated: 2014-07-23  
canonical: https://www.mindstick.com/forum/2025/how-to-select-a-table-from-many-table-while-inserting  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# How to select a table from many table while inserting

I have 4 [tables](https://www.mindstick.com/articles/336597/introduction-of-html-tables-for-web-development)\
\
StdntBtech,StdntPg,StdntUg,StdntDip\
\
I have to insert [values](https://www.mindstick.com/forum/327/sum-textbox-values) into StdntBtech if the course [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) is BE or Btech\
similarly \
\
I have to insert values into StdntPG if the course name is MCA or MSc\
similarly\
I have to insert values into StdntUg if the course name is BSc\
\
similarly \
I have to insert values into StdntDip if the course name is Diploma\
which statement I have to use(IF or Case)if so how the syntax will be?how can I use a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) name in [insert statement](https://www.mindstick.com/forum/157532/why-is-use-the-identity-column-in-the-insert-statement-in-sql)?\
\
\

## Replies

### Reply by Anonymous User

Here is my code for [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) record in a table according to course name from many table while inserting...

```
string tblname = "";        if (txtcourse.Text == "BE" || txtcourse.Text == "Btech")        {            tblname = "StdntBtech";        }        else if (txtcourse.Text == "MCA" || txtcourse.Text == "MSc")        {            tblname = "StdntPg";        }        else if (txtcourse.Text == "BSc" || txtcourse.Text == "BA")        {            tblname = "StdntUg";        }        else if (txtcourse.Text == "Diploma")        {            tblname = "StdntDip";        }        else        {            Response.Write("Please Insert Correct Course Name!!");        }        string st = "insert into " + tblname + " values('" + txtName.Text + "','" + txtCity.Text + "','" + txtcourse.Text + "')";        if (tblname != "")        {            cn.Open();            cmd = new SqlCommand(st, cn);            int executerow = cmd.ExecuteNonQuery();            if (executerow > 0)            {                Response.Write(executerow + " Row's affected");            }            cn.Close();        }        else        {            Response.Write("Please Insert Correct Record");        }
```


---

Original Source: https://www.mindstick.com/forum/2025/how-to-select-a-table-from-many-table-while-inserting

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
