Query to search salaries using IN Clause

  • Greetings,
    I am currently aiming to create a query for educational purposes in SQL 2017 Express as follows:

    Search within Employee Salaries:
    Any Salaries that start with: 10, 12, 15
    The Salaries contain decimal values, so the query will display any salary as follows:
    10.xx
    12.xx
    15.xx
    where xx is a decimal value within the salary being search.
    I've tried several methods and so far, I have been able to execute(with no errors) the following queries. The first two show no output but successful execution, the last one displays outputs but no Hourly Rates beyond xx.00
    First Attempt:
    SELECT FirstName, LastName, HourlyRate FROM Employee
    WHERE HourlyRate IN (10., 12., 15.) AND HourlyRate LIKE '%.__';
    Second Attempt:
    SELECT FirstName, LastName, HourlyRate FROM Employee
    WHERE HourlyRate IN (10., 12., 15.) AND ((HourlyRate *10)%1) >0;

    Third Attempt:
    SELECT FirstName, LastName, HourlyRate FROM Employee
    WHERE HourlyRate IN (10., 12., 15.) AND HourlyRate LIKE '%.%'

    The third attempt displays and output of whole number (10.00, 12.00, 15.00) but doesn't display any  other salaries with additional decimal values.

    I thank you in advance for any guidance or support you could provide
    Sincerely Yours,

  • p.hernandez75 - Monday, February 4, 2019 12:55 PM

    Greetings,
    I am currently aiming to create a query for educational purposes in SQL 2017 Express as follows:

    Search within Employee Salaries:
    Any Salaries that start with: 10, 12, 15
    The Salaries contain decimal values, so the query will display any salary as follows:
    10.xx
    12.xx
    15.xx
    where xx is a decimal value within the salary being search.
    I've tried several methods and so far, I have been able to execute(with no errors) the following queries. The first two show no output but successful execution, the last one displays outputs but no Hourly Rates beyond xx.00
    First Attempt:
    SELECT FirstName, LastName, HourlyRate FROM Employee
    WHERE HourlyRate IN (10., 12., 15.) AND HourlyRate LIKE '%.__';
    Second Attempt:
    SELECT FirstName, LastName, HourlyRate FROM Employee
    WHERE HourlyRate IN (10., 12., 15.) AND ((HourlyRate *10)%1) >0;

    Third Attempt:
    SELECT FirstName, LastName, HourlyRate FROM Employee
    WHERE HourlyRate IN (10., 12., 15.) AND HourlyRate LIKE '%.%'

    The third attempt displays and output of whole number (10.00, 12.00, 15.00) but doesn't display any  other salaries with additional decimal values.

    I thank you in advance for any guidance or support you could provide
    Sincerely Yours,

    Do you know how to use EXISTS? It's a great option for this kind of queries when you need to make advanced comparisons on multiple values.

    SELECT FirstName, LastName, HourlyRate
    FROM Employee e
    WHERE EXISTS(SELECT *
          FROM (VALUES(10., 12., 15.))x (rate)
          WHERE HourlyRate > = x.rate
          AND HourlyRate < x.rate);

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Greetings,
    I am new to SQL and not familiar with the EXISTS Clause. I will research the clause and will execute as explained.
    Thank you very much for your prompt reply and guidance.
    Yours Truly,

  • p.hernandez75 - Monday, February 4, 2019 1:50 PM

    Greetings,
    I am new to SQL and not familiar with the EXISTS Clause. I will research the clause and will execute as explained.
    Thank you very much for your prompt reply and guidance.
    Yours Truly,

    I hope that you were able to understand the usage of EXISTS. If you have any questions, feel free to ask them.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply