Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8828779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:41:08+00:00 2026-06-14T07:41:08+00:00

This is my current SQL query. I need to modify this SELECT 18 BrokerDealerID,

  • 0

This is my current SQL query. I need to modify this

SELECT 
    18 BrokerDealerID,
    5 PortfolioID,
    PeriodEndDate DATE,
    SecurityIdentifier_All.SecurityId,
    MAX(
    (CASE 
        WHEN Securities.Quantity < 0 THEN
        100 + (100 - LocalPriceAmount)
        ELSE
        LocalPriceAmount
     END
        ) /100) Mark
FROM
    Fireball_Reporting..StateStreet_DailyPosition_Second StateStreet 
INNER JOIN
    Fireball_Reporting..SecurityIdentifier_All ON StateStreet.CUSIP = SecurityIdentifier_All.Identifier
INNER JOIN
    Fireball..TradeBySecurityType Securities ON
        Securities.PricingSecurityID = SecurityIdentifier_All.SecurityId AND Securities.Position = 1 AND
(CASE WHEN StateStreet.SecurityName LIKE '% R V %' THEN StateStreet.SharesParValue * -1 ELSE StateStreet.SharesParValue END) = Securities.Quantity
WHERE
    CONVERT(DATETIME, StateStreet.PeriodEndDate) = '2012-10-23' --@PositionDate
GROUP BY
    PeriodEndDate,
    SecurityIdentifier_All.SecurityId

I need to do change in 2nd condition i.e

(CASE WHEN StateStreet.SecurityName LIKE '% R V %' THEN StateStreet.SharesParValue * -1 ELSE StateStreet.SharesParValue END) = Securities.Quantity

I will give you an example.

my select query giving me following output

securityname date       securityid portfolioid type mark               quantity
------------ ---------- ---------- ----------- ---- ------------------ -------------
R V DISH     10/23/2012 4879505    5           CDS  1.0487189900000000 -5000000.0000
R V DISH      10/23/2012 4879505    5           CDS  1.0487189900000000 -2000000.0000
R F DISH    10/23/2012 4879505    5           CDS  0.9512810100000000 3000000.0000

Here above it is giving me 3 records for same security id
When I do MERGE using above result it is only taking 1st record directly if i don’t check that 2nd condition which checks for Quantity but now i want to check only for
When In StateStreet.SecurityName LIKE ‘% R V %’ take the records from above result whose quantity is - if not then take the record whose quantity id +

How could I change that case statement? or directly check for % R V% in select statement where i calculated mark ?
Need technical help.
I’m new to SQL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:41:09+00:00Added an answer on June 14, 2026 at 7:41 am

    Maybe something like:

    (
          (StateStreet.SecurityName LIKE '% R V %' AND Securities.Quantity < 0)
       OR (StateStreet.SecurityName NOT LIKE '% R V %' AND Securities.Quantity >= 0)
    )
    

    I was just guessing about which had the “=” (+ could include 0).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an example version of my current SQL query: SELECT DISTINCT files.* FROM
This LINQ to SQL query From g In Db.Context.Current.Groups Select g.GroupID generates this SQL:
I need help with a SQL Query I have this table likes friend friend2
I never used if-else or case inside a sql-query, but I guess I need
I'm a postgresql user and I'm trying to follow this : http://www.postgresql.org/docs/current/interactive/sql-createtrigger.html CREATE TRIGGER
We have this current database which we need to replace some tables by anther
I have an SQL query I get from a configuration file, this query usually
I'm having trouble creating a query. I need to create a SQL query where
I want to implement following logic in my SQL query: If some date is
I need to generate a ms-word document from a pl/sql query to export a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.