How to Insert Data Fetched from another Table in SQL

In this article I am going to explain how to insert data fetched from another table in SQL.
  • 2368

Introduction

In this article I am going to explain how to insert data fetched from another table in SQL. We can insert data into a table fetched from one or more other table in SQL. To insert this type of data we use subquery.

We right sub query in insert statement at the place of values. Result derived from subquery works as input or inserted value.   

Statement that create a table

create table mcntemp

(

invoiceid int not null,

vendorid int not null,

invoiceno varchar(15),

invoicetotal money,

paymenttotal money,

creadittotal money

)

Statement that insert data in Table

INSERT INTO mcntemp

SELECT * FROM dbo.mcninvoices

WHERE invoicetotal-paymenttotal-creadittotal>0

Statement show data in mcntemp table

Clipboard02.jpg


© 2020 DotNetHeaven. All rights reserved.