Modifying SQL query

Mitchell, Jennifer 1 Reputation point
2021-09-24T11:50:21.96+00:00

I have no experience with SQL however I have a pre-exisiting query and I want to add a filter that states in-service as Y and dates between 21-Aug-21 through -11-Sep-21

See below query and screenshot

,t5 AS
(Select/+parallel(8)/ ACCT_ID,SA_ID, char_type_cd Deposit_Char,char_val Deposit_Char_Value, Quoted_Deposit_Amount,Deposit_on_Hand,START_DT Quote_Date,
(case when Deposit_on_Hand is null then Quoted_Deposit_Amount else Quoted_Deposit_Amount-Deposit_on_Hand end) Deposit_Amt_Unpaid
From (
SELECT /+parallel(8)/
SA.ACCT_ID,SA.SA_ID,sc.char_type_cd,sc.char_val, sa.tot_to_bill_amt Quoted_Deposit_Amount,sa.START_DT,
row_number() over(partition by SA.ACCT_ID order by sa.START_DT desc) Deposit_rnk,
(sum(ft.tot_amt)*(-1)) Deposit_on_Hand
from cisadm.ci_sa sa
left join cisadm.ci_ft ft on (sa.sa_id = ft.sa_id)
left join cisadm.ci_SA_Char sc on (sa.sa_id = sc.sa_id)
where SA.SA_TYPE_CD IN ('O-DEPRES', 'O-DEPCOM', 'O-EXCRDP')
AND SA.SA_STATUS_FLG IN ('20')
group by SA.ACCT_ID,SA.SA_ID,sc.char_type_cd,sc.char_val, sa.tot_to_bill_amt,sa.START_DT)
Where Deposit_Rnk=1
)

134997-image.png

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,702 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,798 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,245 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Olaf Helper 40,741 Reputation points
    2021-09-24T12:33:47.79+00:00

    SELECT /+parallel(8)/

    I know this query hint "parallel" from Oracle https://docs.oracle.com/cd/E11882_01/server.112/e41573/hintsref.htm#CHDJIGDG
    And the screenshot is SqlPlus, also Oracle.
    Right? Because this a forum for Microsoft SQL Server

    Anyway, please post table design as DDL, some sample data as DML statement and the expected result.