parametrized sql query

1

Write a query that shows the last name (with the first letter in uppercase and the others in lowercase) and the length of the last name of all employees whose name starts with L, P or R. Label each column appropriately. Sort the results by the last names of the employees.

I already have everything except the part of the length this is the code I have:

SELECT UPPER(LEFT(apellido, 1)) + LOWER(SUBSTRING(apellido, 2, LEN(apellido))) as apellidos 
FROM empleados 
where apellido LIKE 'L%' OR 
      apellido LIKE 'P%' OR 
      apellido LIKE 'R%' 
group by apellido  
having count (*) >= 1 
ORDER BY apellido 
    
asked by Samuel Ignacio Susana Confesor 13.06.2017 в 19:44
source

1 answer

0

I made some changes to your query:

SELECT UPPER(LEFT(apellido, 1)) + LOWER(SUBSTRING(apellido, 2, LEN(apellido))) as apellidos,
    LEN(apellido) AS 'LongitudApellido' 
    FROM empleados 
    where apellido LIKE '[LPR]%'
    GROUP BY apellido
    ORDER BY apellido
  • The length of any string you get with the LEN() function
  • Not that it was wrong, but modify the LIKE simply to make it shorter, it works the same.
  • answered by 13.06.2017 / 19:52
    source