Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

convert decimal to int in case condition

$
0
0
i have a table exam_setup CREATE TABLE exam_setup(setup_id INT,sub_id INT,assignment decimal(4,1),attendance decimal(4,1),INT_1 decimal(4,1),INT_2 decimal(4,1))table values are,sub_id = 75,assignment = 25.0attendance = 15.5INT_1 =0.0INT_2 =0.0I have to fetch the values likeassignment = 25attendance = 15.5INT_1 =0INT_2 =0 if decimal point is 0 then have to return integer value only.. but the below query doesn't work, why?SELECT CASE WHEN assignment LIKE '%.0' THEN CONVERT(INT,assignment) ELSE assignment END, CASE WHEN attendance LIKE '%.0' THEN CONVERT(INT,attendance) ELSE attendance END, CASE WHEN INT_1 LIKE '%.0' THEN CONVERT(INT,INT_1) ELSE INT_1 END, CASE WHEN INT_2 LIKE '%.0' THEN CONVERT(INT,INT_2) ELSE INT_2 ENDFROM exam_setupWHERE sub_id = 75

Viewing all articles
Browse latest Browse all 3145

Latest Images

Trending Articles



Latest Images