How to combine 2 SQL statements into one?
A quick and dirty way would be to have a script for the next X years.
Something like:

IF db_id('ctx_2015_log') is not null
EXECUTE('
BEGIN
    USE select quotename(db_name(db_id(''ctx_2015_log'')))
    DBCC SHRINKFILE(ctx_2015_log)
    BACKUP LOG ctx_2015 TO DISK=''NUL:''
    DBCC SHRINKFILE(ctx_2015_log)
END
');

IF db_id('ctx_2016_log') is not null
EXECUTE('
BEGIN
    USE select quotename(db_name(db_id(''ctx_2016_log'')))
    DBCC SHRINKFILE(ctx_2016_log)
    BACKUP LOG ctx_2016 TO DISK=''NUL:''
    DBCC SHRINKFILE(ctx_2016_log)
END
');


You can build this statement with: 

DECLARE @i int =2015
DECLARE @ti varchar (4)
DECLARE @command varchar (max)

WHILE @i&lt;2020
BEGIN
    SET @ti=CONVERT(varchar(4), (@i))
    SET @command=
        'IF db_id(''ctx_'+@ti+'_log'') is not null
        EXECUTE(''
        BEGIN
            USE select quotename(db_name(db_id(''''ctx_'+@ti+'_log'''')))
            DBCC SHRINKFILE(ctx_'+@ti+'_log)
            BACKUP LOG ctx_'+@ti+' TO DISK=''''NUL:''''
            DBCC SHRINKFILE(ctx_'+@ti+'_log)
        END
        '');
        '
    PRINT @command
    SET @i+=1
END