Tharindu Tharindu - 7 months ago 15
SQL Question

Getting Multiple Sql commands operated in C#

I'm trying to get a divided count value for a specific name as follows

var query = "select round((cast(x.num as float) / cast(y.num as float)*100),0) as Q from (select count(*) as num from VisitDistribution where Name = '" + data.K + "' and Visits ='" +
c +
"') x join (select count(*) as num from VisitDistribution where Name = '" + data.K + "' ) y on 1=1 ";


What I want to do is execute the following command in the same method

var query = "select round((cast(x.num as float) / cast(y.num as float)*100),0) as Q from (select count(*) as num from VisitDistribution where Name = '" + data.C + "' and Visits ='" +
c +
"') x join (select count(*) as num from VisitDistribution where Name = '" + data.C + "' ) y on 1=1 ";


I need to get the values from these queries to separate columns using angular js. I can do that but the problem is I can't execute these 2 queries at the same time and add the resulting values to the respective columns to a list.

Answer
    var query = "select round((cast(x.num as float) / cast(CASE WHEN y.num = 0 THEN 1 ELSE y.num END as float)*100),0) as Q, round((cast(a.num as float) / cast(CASE WHEN b.num = 0 THEN 1 ELSE b.num END as float)*100),0) as R from 
                (select count(*) as num from VisitDistribution  where Name = '" + data.K + "' and Visits ='" + c + "' ) x 
                join (select count(*) as num from VisitDistribution where Name = '" + data.K + "' ) y on 1=1
                join (select count(*) as num from VisitDistribution  where Name = '" + data.C + "' and Visits ='" + c + "' ) a on 1=1
                join (select count(*) as num from VisitDistribution where Name = '" + data.C + "' ) b on 1=1"
Comments