question

phani10695 avatar image
phani10695 asked

how to use two calculated columns in same select statement

Hi how to rewrite the following question, here 'history' table, used\_life int datatype, ul\_units varchar, ul\_units may contain data of firings, starts, landings, how to use two calculated columns in same select statements here user will enter history of flights in hh and mm in two texboxes i am converting into minutes and storing, it is a simple select if it is like this select used_life/60 as hrs,used_life%60 as mns but how to write this select case when (used_life>=60 and ul_units='HH:MM') then (used_life/60) else used_life end as used_life_hrs case when (used_life>=60 and ul_units='HH:MM') then (used_life%60) else used_life end as used_life_hrs from history here i have to do all this conversion only when the ul_units are HH:MM and used_life>=60 else i have to print the data as it is above query giving syntax error can anyone help Thanks in Advance
calculations
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Usman Butt avatar image
Usman Butt answered
@phani10695 Please move your question to the default forum. This is only for the site discussions. Moreover, The syntax error is there, since you are missing a comma(,) in between the columns. i.e. ...then (used_life/60) else used_life end as used_life_hrs,... OR if you need to add these fields then remove naming the first column alias and add a + i.e. ...then (used_life/60) else used_life end +..... If something else is desired, please let us know
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.