sql - How to merge a select statement with a new dynamic values as columns? -


in sql server code, have select statement

select distinct      a.hirelastname,      a.hirefirstname,      a.hireid,      a.position_id,      a.barnumber,      a.archived,      a.datearchived,      b.position_name newhire  join position b on a.position_id = b.position_id join workperiod c on a.hireid = c.hireid a.archived = 0 , c.inquiryid not null  order a.hireid desc, a.hirelastname, a.hirefirstname 

and want add new column it. column not column table, used store float calculation make existing columns.

the number calculated this: @acc a.hireid above select statement.

cast((select count(*) hire_response hireid = @acc , (hireresponse = 0 or hireresponse = 1)) float) /  cast((select count(*) hire_response hireid = @acc) float) 

how can this? thanks.

this should it

select distinct      a.hirelastname,      a.hirefirstname,      a.hireid,      a.position_id,      a.barnumber,      a.archived,      a.datearchived,      b.position_name,     cast((select count(*) hire_response hireid = a.hireid ,         (hireresponse = 0 or hireresponse = 1)) float) /       cast((select case when count(*) = 0 1 else count(*) end hire_response hireid = a.hireid) float) myspecialcolumn newhire  join position b on a.position_id = b.position_id join workperiod c on a.hireid = c.hireid a.archived = 0 , c.inquiryid not null  order a.hireid desc, a.hirelastname, a.hirefirstname 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -