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 =...
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.