I have got a table called tblCar
and there are ID
, CarNumber
and other 32 fields.
32 columns are filled as s1,s2,s3,.......,s32
since they are dedicated to remark whether it is for SEATS which are available(A), booking(B), and Sold(S).
I want to count available seats, booking seats and sold out seats from that database. how should i write a query?
Is there anyway to count from string S
, B
and A
from 32 different columns in database?
What i want to show is like that..... S = 20, B = 10, A = 2;
SqlCommand cmd = new SqlCommand(
"Select count(*)
FROM tblCar
WHERE s1= 'S' or s2= 'S' or s3= 'S'
or s4= 'S' or s5= 'S' or s6= 'S'
or s7= 'S' or s8= 'S' or s9= 'S'
or s10= 'S' or s11= 'S' or s12= 'S'
or s13= 'S' or s14= 'S' or s15= 'S'
or s16= 'S' or s17= 'S' or s18= 'S'
or s19= 'S' or s20= 'S' or s21= 'S'
or s22= 'S' or s23= 'S' or s24= 'S'
or s25= 'S' or s26= 'S' or s27= 'S'
or s28= 'S' or s29= 'S' or s30= 'S'
or s31= 'S' or s32= 'S' ", con
);
count += cmd.ExecuteNonQuery();
this is how I work for "Sold" field.but it showed only count = -128.i did initialized count as 0