Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 error while inserting count into temp table

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2009-07-20 : 11:35:08
hi all
I'm getting an error while collection from few of SQL as below
I want to collect count from few below SQL into one TEMP table

I'm getting an error as ----
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
================================================================
select (
select 'KC_PROD_SUM',count (*)
from
(SELECT *
FROM [KC_PROD_SUM]
where [KC_PROD_SUM_MES_PRODU_DATE_DT] <= getdate()
) A
---------------------------------------------------------------------------------------------
union all
---------------------------------------------------------------------------------------------
select 'KC_PROD_WASTE',Count(*)
from
(
SELECT *
FROM [KC_PROD_WASTE]
where [KC_PROD_WASTE_MES_PRODU_DATE_D] <= getdate()
) as B

) as inline

into #DataPurgeCountTable
================================================================

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-07-20 : 11:53:23
select desc, cnt into #DataPurgeCountTable
from (
select 'KC_PROD_SUM' as desc,count (*) as cnt
from
(SELECT *
FROM [KC_PROD_SUM]
where [KC_PROD_SUM_MES_PRODU_DATE_DT] <= getdate()
) A
---------------------------------------------------------------------------------------------
union all
---------------------------------------------------------------------------------------------
select 'KC_PROD_WASTE' as desc,Count(*) as cnt
from
(
SELECT *
FROM [KC_PROD_WASTE]
where [KC_PROD_WASTE_MES_PRODU_DATE_D] <= getdate()
) as B

) as inline
Go to Top of Page
   

- Advertisement -