Link to home
Start Free TrialLog in
Avatar of John Miller
John Miller

asked on

SQL Server

I have a SP in which i need to add one condition to check multiple databases by using sys.dm_database_encryption_keys table. 

when encryption_state is 2 and percentage_completed is 0 in the results it should print. Below is my query



DECLARE @Test varchar(10)
SELECT @Test = Database_ID from 
                             sys.dm_database_encryption_keys  
WHERE Encryption_state = 2 and complete_percentage = 0
If (@test not NULL)
Begin
PRINT("ALTER DB NAme")

If i have multiple DB's which meets the about. It should PRINT multiple ALTER statements with DB Names
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Why not have something like...

select 'Alter database ' + DB_NAME(database_id)
from  sys.dm_database_encryption_keys 
where 1 = 1
  and Encryption_state = 2 
  and complete_percentage = 0

Open in new window

Please let us know your ultimate requirement. That way if possible and appropriate a better solution can be provided.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.