Re: Cross tab based on DateDIFF



Geoff,

Is this what you are after?

SELECT
SUM (CASE
WHEN Col1 >= 0 THEN 1
ELSE 0
END) AS NonNegative,
SUM (CASE
WHEN Col1 >= 0 THEN 0
ELSE 1
END) AS Negative
FROM YourTable

--RLF

"Geoff" <Geoff@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:253BF539-8139-4E63-B824-73440A6302E9@xxxxxxxxxxxxxxxx
I'm trying trying to build a crosstab query using a Case statement to
count
the number of records in one column with the DateDiff >=0 and the other
column to be a count of the Records with the DateDiff <0. I can do this
easlily in MS Access with the IIF Function in a crosstab query but I can't
get the Sql Statement to work in an MS Sql 2000 View


.



Relevant Pages

  • Re: Optimising the Query
    ... Slightly reformatting your SQL statement: ... SUM (CASE WHEN ... Do you need the outer join? ... Here's the explain plan generated by the query: ...
    (comp.databases.oracle.misc)
  • Re: Optimising the Query
    ... Slightly reformatting your SQL statement: ... SUM (CASE WHEN ... Do you need the outer join? ... Here's the explain plan generated by the query: ...
    (comp.databases.oracle.misc)
  • Re: Help with an SQL Statement plzzzzz
    ... I would like an sql statement that count the sum of the phone number that appears more than once only. ... I've called the source table tbname. ... SELECT tbname.name, tbname.volumes, CountAS [Total repeat Volumes by name] INTO tb2 ...
    (microsoft.public.access.modulesdaovba)
  • Re: Text box value based on sum of another text box
    ... What happens is Access creates an SQL statement it passes to Jet. ... "T: CommandeIngenierie" ... Variable to be calculated from sum of Value variable ...
    (microsoft.public.access.forms)
  • Re: Is There Easier Way to Calculate This Percentage in T-SQL?
    ... David, thanks VERY MUCH for the tips. ... Will this one large SQL statement also provide the 6 values I need ... values for CountVar1 to CountVar6? ... > In this query COUNT has the advantage over SUM that it will return 0 rather ...
    (microsoft.public.sqlserver.programming)