SELECT avg(datediff(day,dtRequestDate,dtDeliveryDate))/30.5 from orders
where substring(strName,1,1) = ?
As written, I enter a letter of the alphabet and I get a result. Instead I would like to have it create a table with a result for each letter of alphabet.
SELECT substring(strName, 1, 1) AS first_letter,
avg(datediff(day,dtRequestDate,dtDeliveryDate))/30.5 AS avg_days
into dbo.new_table_name
from orders
group by substring(strName, 1, 1)