dimanche 11 septembre 2016

IF-ELSE SQL Statement

I'm having a problem executing this SQL statement. I am new to TSQL and I have no idea how to fix this. Everytime I execute this, I get the error:

An expression of non-boolean type specified in a context where a condition is expected, near ')'.

Incorrect syntax near the keyword 'else'.

if
SELECT Num from users where SUBSTRING(CAST(Num AS VARCHAR(6)),1,2) = 14
     print 'Batch 2014';
else
     print 'Batch 2013';

What I'm trying to do here is to search in my table all users with '13' as the first 2 numbers in the column 'Num', and then print 'Batch 2014' else 'Batch 2013' Please help :) thank you

Aucun commentaire:

Enregistrer un commentaire