Mr John Mr John - 6 months ago 18
SQL Question

SQL Server - 2008 Column Data Type

I have the below Case Statment and I'm inserting this into a new table. The column under the new table is Varchar but I need it as an INT. I have changed the data type using the Alter statment but I frequenctly delete and create the same table. Is there a way to have the new table create the data type of INT instead of varchar for the below syntax?

CASE WHEN F.END_DATE IS NOT NULL OR F.REASON IS NOT NULL THEN '0' ELSE '1' END Enrolled'

Answer

Get rid of the single quotes around 0 and 1:

CASE WHEN F.END_DATE IS NOT NULL OR F.REASON IS NOT NULL  THEN 0 ELSE 1 END Enrolled'