Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Calculate Columns from different tables loading into single table SQL

$
0
0

Hello Guru's

I am facing an issue with calculated columns. I am having few calculated columns and I want that to insert into a table or create a SQL COMMAND.

for ex: column 1 must  load query1 output

and column 2 must load query2 output

for ex: column 1 will load query1 output

and column 2 will load query2 output

The below query1 is from table PFCPHSMD

SELECT COUNT(DISTINCT SMD_PNO)  AS SMD_PNO FROM PFCPHSMD
WHERE CONVERT(Date,SMD_ODOC_DT)>= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0)
AND  CONVERT(Date,SMD_ODOC_DT) <= DATEADD(MILLISECOND, -3,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)) SMD_STTS='F'
 AND SMD_SPMD='A'
  GROUP BY  SMD_PDC,SMD_CMP_KND

Out Put:

SMD_PNO 

  16

  17

     6

The below is query 2 is from table PFCICIMT

SELECT  SUM(IMT_OHND_AME) AS IMT_OHND_AME FROM PFCICIMT
WHERE CONVERT(Date,IMT_ODOC_DT)>= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0)
AND  CONVERT(Date,IMT_ODOC_DT) <= DATEADD(MILLISECOND, -3,DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0))
AND AND IMT_INV_ATYP='LDC'
  GROUP BY  IMT_PDC,IMT_CMP_KND 

 IMT_OHND_AME

2995

 560

300

Now I have another table and I have to some how load the above results into my existing table Columns.

Example : Say my Table Name as Test and having Column1 and Column2 as Columns

now I want Query1 values into Column1 and Query2 values into Column2

my output should look like below

Column1   Column2

  16             2995

  17               560

     6                     300



Dasari

 

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>