Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to process multiple hardcoded values in SQL?

How would I do this in SQL Server? (I know it won't run as written but it illustrates the question better than I can explain)

SELECT SQRT(number) WHERE number IN (4,9,16,25)

It would return multiple rows of course

like image 489
draca Avatar asked Dec 09 '22 12:12

draca


1 Answers

you can use table value constructor

select sqrt(number) 
from (
    values (4),(9),(16),(25)
) as T(number)

or use union all

select sqrt(number)
from (
    select 4 union all
    select 9 union all
    select 16 union all
    select 25
) as T(number)

sql fiddle demo

like image 52
Roman Pekar Avatar answered Dec 21 '22 04:12

Roman Pekar