Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Sql :: check sql query executed wp 
Sql :: transaction and commit trong sql server 
Sql :: sqlite escape single quote 
Sql :: primary key start from number 
Sql :: sakila database erd postgresql 
Sql :: oracle date winter time 
Sql :: date functions 
Sql :: SQL Copy Table Schema Only 
Sql :: least orders 
Sql :: db visualizer mssql 
Sql :: apex call duration 
Sql :: Select all columns except one in MySQL? 
Sql :: sql query to delete row by id 
Sql :: select distinct records in sql with maximum time desc 
Sql :: postgres grep entire database 
Sql :: how to change the field size of an existing column 
Sql :: OFFSET consulta mysql 
Sql :: sqlite ignore index 
Sql :: ksqldb limit pull query ksql kafka 
Sql :: sqlalchemy sequence postgresql 
Sql :: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it (SQL: select * from `featured_categories` limit 1) 
Sql :: while in plsql 
Sql :: SQL sort on a calculation 
Sql :: SQL SERVER microsoft How to Add Column at Specific Location in Table 
Sql :: sql into vs insert into 
Sql :: Apache Derby: Create SQL Dump with data 
Csharp :: c# delete file if exists 
Csharp :: aspx textarea 
Csharp :: check if gameobject is active 
Csharp :: c# copy file to directory 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =