Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

store case result sql

declare
    @val int = 0;

select     
    @val = CASE 
        WHEN MONTH([DATE]) = MONTH(getdate()) AND
        YEAR([DATE]) = YEAR(getdate())
        THEN SUM(PROFIT)
        OVER (PARTITION BY [Name], 
            MONTH([DATE]), YEAR([DATE])) 
        ELSE 0 
        END 
FROM table_name
WHERE [Name] = @Name AND
      MONTH([DATE]) = @Month AND
      YEAR([DATE]) = @Year

print @val
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #store #case #result #sql
ADD COMMENT
Topic
Name
9+3 =