Help on Count query

Posted by Vijayar under C# on 6/17/2011 | Points: 10 | Views : 1802 | Status : [Member] | Replies : 3
select Datasource_id,Commitment-y.total as Requirement,DataSourceName(
select y.total as count1,DataSourceId from
(Select sum(X.applicantid) As total,X.DataSourceId
from (
select r.DataSourceId,COUNT(*) applicantid
from RCNewApplicants r Where EntryBY=17 group by r.DataSourceId
union all
select DataSourceId, COUNT(*) applicantid from UploadCsvFile where
CreatedBy=17 group by DataSourceId
) as X group by X.DataSourceId) as y ) From SourceMaster



i am getting error while executing the query.please help me to sort out the problem.it;s very urgent

vijaya


Responses

Posted by: Reena_jainy2k1 on: 6/17/2011 [Member] Starter | Points: 25

Up
0
Down
hi,

The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. so number of column should be same in both table like this

SQL UNION ALL Statement
SELECT id, Sales FROM TABLE1
UNION ALL
SELECT Lid,Sales FROM TABLE2

Hope this will help you

Reena Jain
Project Manager

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 6/17/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
the number of columns are same and are of same type but i am getting the error as Error
SQL Server Database Error: Incorrect syntax near the keyword 'select'.


select Datasource_id,Commitment-y.total as Requirement,DataSourceName(
select y.total as count1,DataSourceId from
(Select sum(X.applicantid) As total,X.DataSourceId
from (
select r.DataSourceId,COUNT(*) applicantid,entryby,applicantname
from RCNewApplicants r Where EntryBY=17 group by r.DataSourceId
union all
select DataSourceId, COUNT(*) applicantid,,createdby,csvfilename from UploadCsvFile where
CreatedBy=17 group by DataSourceId
) as X group by X.DataSourceId) as y ) From SourceMaster



i want to whether the sybtax is correct or not
help me

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 6/22/2011 [Member] Starter | Points: 25

Up
0
Down


Hi, i am want to find out the difference between and commitment value,datasource_id,DataSourceName which is available in sourcemaster,i am writing a query like this but i am not getting result.Please help me



select Datasource_id,Commitment-y.total as Requirement,DataSourceName(
select y.total as count1,DataSourceId from
(Select sum(X.applicantid) As total,X.DataSourceId
from (
select r.DataSourceId,COUNT(*) applicantid,entryby,applicantname
from RCNewApplicants r Where EntryBY=17 group by r.DataSourceId
union all
select DataSourceId, COUNT(*) applicantid,,createdby,csvfilename from UploadCsvFile where
CreatedBy=17 group by DataSourceId
) as X group by X.DataSourceId) as y ) From SourceMaster

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response