Home Forums SQL Server 2008 T-SQL (SS2K8) Need help with a script to identify count of negative and positive numbers in a record RE: Need help with a script to identify count of negative and positive numbers in a record

  • Actually, I found even more elegant way:

    SELECT *

    FROM tablename

    CROSS APPLY(SELECT SUM(SIGN(c) + ABS(SIGN(c)))/2 AS Positive

    ,ABS(SUM(SIGN(c) - ABS(SIGN(c)))/2) AS Negative

    FROM (VALUES (col1),(col2),(col3),(col4),(col5)) c(c)) calc

    ... however, I will not be surprised if CASE WHEN outperform all of mathematical-puzzle based.

    It requires some testing, but I have no time for this right now :Whistling:

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]