SELECT ChgBillMonth
,CONVERT (VARCHAR(100),SUM(CAST(ChargeAmt as Money)),1) as ChargeAmt
,sum(CurrentBalance) as Balance
,sum(ChargeAmt) as ChargeAmtSum
--,sum(CurrentBalance) as Balance
FROM #T
WHERE ChgBillMonth='8/1/2013'
GROUP BY ChgBillMonth
if it is SQL 2005, use CTE
with Detail(empcount,busunitdesc)
as
(
select count (distinct employeeid), busunitdesc
from invinvoicedetail inv
inner join invinvoiceheader b on b.invoiceid = inv.invoiceid
inner join ssbusunit u on u.busunitid = inv.busunit
where b.invoicedate between @StartDate...
this book helped me to explore more behind the T-SQL
http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139#readerhttp://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139#reader
in your derived table 'Month(dteEffectiveDate)' column has been defined as 'Monthy' and AVG(nbrFuelSurcharge) as 'FSCY'.
run this code alone and see the output and columns
SELECT
'Monthy'=Month(dteEffectiveDate),
'FSCY'=AVG(nbrFuelSurcharge)
FROM Mother.dbo.tblFuelSurcharge
GROUP by...
That was very informative George. I wasn’t sure that there is a workaround to convert data type using CASE so i thought that my logic was wrong. So i built that logic at the report level.
Thanks for the suggestion.
Hi,
I want to format the data as below for a report.
here is just a sample of what i am doing...
create table #test
(Header_1 varchar(20),
Month_1 numeric(10,2))
;
insert into #test values('Sales',120)
insert into #test values('Sales%',2.45)
;
select case when charindex('%',[Header_1])=0...
MikeBinKC,
I think SQLSister explained it clearly.
you can further read about derived table here..
http://www.sqlservercentral.com/articles/Performance+Tuning/derivedtablebasics/597/
try this...
select a.EmployeeName,
a.LeadName,
a.PhoneNumberCalled,
a.DateCalled
from MyCallRecord a
inner join (
select EmployeeName,
LeadName,
min(DateCalled)DateCalled
from MyCallRecord
group by EmployeeName,LeadName
) b
on a.EmployeeName =...
you could try this.
select a.AccountRef_FullName,sum(a.SumTotal)SumTotal
from ( 'your first query'
union all
'your Second query'
) a
group by a.AccountRef_FullName
if it is SQL 2005, you could try this.
i used multiple CTEs along with the ROW_NUMBER() function.
with SALES1 as
(
select SalesPerson,State,sum(Cost) Tot_Cost
from InvoiceTable
group by SalesPerson,State
),
SALES2 as
(
select SalesPerson,State, row_number() over(partition by State order by...
try this..
select distinct a.NumID, count(b.NumID)NumID_Count
from Table_1
left join Table_2
on a.NumID = b.NumID
group a.NumID
DISTINCT command gives you only unique records based on the columns you have defined.
Column list (NumID,Date,Item,Item2) is NOT unique, qry returns duplicate...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.