Search code examples
sqlsql-server

How to make multiple select into on the same table?


I have a little problem right now I'm doing Stored Proc in SQL server. I want to get some results from multiple tables and put it into a temporary table. So I thought I could use a "Select into" statement which works fine until I decided to add multiple select into the temporary table. For example: Here's my code:

while @Compteur <= @wrhCodeEnd
  select lp.lotQty ,lp.lotID into ZeTable from TB_lotLot ltlt
  inner join TB_lotPal lp on ltlt.lotID=lp.lotID
  inner join TB_palSuper ps ON lp.spID=ps.spID
  inner join TB_expExpeditionLot eel ON eel.lotID=lp.spID
  where ps.wrhID <> @Compteur and
   ltlt.wrhID = @Compteur and
   lp.lotID not in(select ZeTable.lotID from ZeTable)

the thing is I don't know if I can make multiple select into on the same temporary table and I also want to check with a where clause the information in the table is not already there.

Thanks in Advance


Solution

  • You can create temporary table and can use insert statement to add records with required columns and can drop it after use.