Mohamed Mohamed
Mohamed Mohamed

Reputation: 33

How to convert horizontal row into vertical SQL Server

Query:

Select 
    COUNT(aciklama)as Permitted,   
    (Select COUNT(aciklama) 
     from Uyari 
     where Aciklama like '%Blocked%') as Blocked 
From 
    Uyari 
where 
    Aciklama like '%Permitted%'

Output:

Permitted     Blocked
----------------------
    74         9194

I want result like this:

Permitted   ...      74
Blocked    ...     9194  

Could any one help?

Upvotes: 3

Views: 1467

Answers (1)

sgeddes
sgeddes

Reputation: 62851

Here's one option using union all

select 'Permitted' action, COUNT(aciklama) as result
from Uyari 
where Aciklama like '%Permitted%'
union all
select 'Blocked' action, COUNT(aciklama)   
from Uyari 
where Aciklama like '%Blocked%'

Upvotes: 2

Related Questions