Click here to Skip to main content
15,916,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
create Table #table1(Name varchar(50),ChicksQuantity int,Chicksplaceddate datetime,Billablechicks int,freechicks int,Mortality int,Chickrate float,TotalAmount float,CashRecieved float)
insert into #table1

select A.agentname as Name ,A.Chicksqty as ChicksQuantity,A.Chicksplaceddate as Chicksplaceddate, A.billablechicks as Billablechicks,
 A.freechicks,A.mortality,A.Chickrate,A.Totalamount,A.Cashrec,
 F.farmername as Name,F.Chicksqty as Chicksquantity,F.chicksplaceddate,F.billablechicks,F.freechicks,
 F.mortality,F.Chickrate,F.Totalamount,F.Cashrec,I.farmername as Name,I.noofchicks as chicksquantity,I.mortality,I.Chicksplaceddate from  k_Master_Agentchicksales A
inner join k_Master_IntegrationChickSale I on A.hatchid=I.hatchid
inner join k_Master_Farmerchicksales F on F.hatchid=A.hatchid where A.updatedon between '2013-04-01 00:00:00.000' and '2014-03-31 00:00:00.000'


select * from #table1






i want only 9 columns report using three tables....
i know create table total columns and inserting columns must be same but how can i differentiate plz help me.....
Posted

1 solution

You ware using Three select statements under the single Insert Query which is not correct. For a single insert single select can act as input. So write three statements like this this single will do the work if you have multiple record.

SQL
INSERT INTO #table1 
SELECT A.agentname as Name, 
	A.Chicksqty as ChicksQuantity, 
	A.Chicksplaceddate as Chicksplaceddate, 
	A.billablechicks as Billablechicks,
	A.freechicks,
	A.mortality,
	A.Chickrate,
	A.Totalamount,
	A.Cashrec

FROM k_Master_Agentchicksales A
    INNER JOIN k_Master_IntegrationChickSale I on A.hatchid=I.hatchid
    INNER JOIN k_Master_Farmerchicksales F on F.hatchid=A.hatchid
WHERE A.updatedon between '2013-04-01 00:00:00.000' and '2014-03-31 00:00:00.000'
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900