Showing posts with label statment. Show all posts
Showing posts with label statment. Show all posts

Monday, March 19, 2012

Combine 2 select statment result in one table

Hi All,
I am new in the Fourm.
I have a one Problem. I have a two select stament that are return 2-2 column that are in the differnent table.
I want that return in one table......

Ex I am writing 2 select statment below..
1. select count(product.ProductID) as productCount,AffiliateHits.affiliateID,product.Name as [Name],product.ProductID
from AffiliateHits,product
where AffiliateID like 'SELF'--@.affiliateID
and product.ProductID=AffiliateHits.ProductID
group by product.ProductID,AffiliateHits.affiliateID,product.Name

2.
select count(*)as OrderCount,orderdetail.productid from [order],OrderDetail
where [order].sourceID like @.affiliateID and
[order].addedon between @.fromDate AND @.toDate AND
[order].orderID=OrderDetail.orderid AND
OrderDetail.ProductID in (select distinct(productid)from AffiliateHits where AffiliateID like @.affiliateID)
group by orderdetail.ProductID

Plz Reply asap.

Thankx

Two ways...UNION ALL, or CROSS JOIN. UNION can be used to take two sets and combine them, column by column. So:

select column1
from table1

UNION ALL

select column2
from table2

This might produce a result like

column1
-
1
2

I don't think this is what you need. Cross join

select <columnNames>
from (select column1
from table1)
CROSS JOIN --or possibly join, if there is some relationship between the sets and multiple rows
( select column2
from table2)
--ON --if these are multi row sets (you might JOIN ON productId)

This might produce a set like (if each set returned one row)

column1 column2
--
1 2

I cant tell from your group by if either of these make sense, because your two sets have different group by clauses. Does this help? Can you simplify your example so one of us can make you a functional (with data) example?

Wednesday, March 7, 2012

Column Totalling Question

I am trying to total a column and I am not sure how to do this.
I have an IIF statment in a textbox in my table in which subtracts 2
columns, sees if the calculated value is less than zero, and if the value is
less than zero display 0 else display the value. See Below
=IIF((MSRptISCClass.ISC.intGetSumORHours(Fields!EmployeeNumber.Value))-(MSRptISCClass.ISC.intGetORHoursLogged(Fields!EmployeeNumber.Value))
<
0,0,(MSRptISCClass.ISC.intGetSumORHours(Fields!EmployeeNumber.Value))-(MSRptISCClass.ISC.intGetORHoursLogged(Fields!EmployeeNumber.Value)))
What I want to do is take the sum of all these results in the footer of the
table but I cant wrap a Sum aggregate function around the above statement and
I cant use the running value function because it doesn't take in account the
negative values that I handle in the text box. ANY SUGGESTIONS!!!
DONI had a situation like this. I ended up creating total rows in a stored
procedure along with the other detail rows. To distinguish a row, I added a
rowtype column. I used the CASE statement within the stored procedure to
calc totals. Hope this helps!
"dillig" <dillig@.discussions.microsoft.com> wrote in message
news:B5BE15B7-817A-4755-8422-26D9A4C28896@.microsoft.com...
>I am trying to total a column and I am not sure how to do this.
> I have an IIF statment in a textbox in my table in which subtracts 2
> columns, sees if the calculated value is less than zero, and if the value
> is
> less than zero display 0 else display the value. See Below
> =IIF((MSRptISCClass.ISC.intGetSumORHours(Fields!EmployeeNumber.Value))-(MSRptISCClass.ISC.intGetORHoursLogged(Fields!EmployeeNumber.Value))
> <
> 0,0,(MSRptISCClass.ISC.intGetSumORHours(Fields!EmployeeNumber.Value))-(MSRptISCClass.ISC.intGetORHoursLogged(Fields!EmployeeNumber.Value)))
> What I want to do is take the sum of all these results in the footer of
> the
> table but I cant wrap a Sum aggregate function around the above statement
> and
> I cant use the running value function because it doesn't take in account
> the
> negative values that I handle in the text box. ANY SUGGESTIONS!!!
> DON