Friday, 15 February 2013

sql - add extra columns in a SELECT INTO statement -



sql - add extra columns in a SELECT INTO statement -

i doing select statement create new table values in table. want add together 2 columns onto newly created table (pol_eff_dt, pol_exp_dt) , create them null (these columns exist in source table otherwise pull data). need create sure come on datetime types. how can cast them way? i've tried lot of things, nil compile.

select distinct bnd_ser_nbr, trans_nbr, uws_product_cd, bill_id, null pol_eff_dt, null pol_exp_dt er_ro_urs_prem_detail urs_prem_detail_interim

you can seek casting null explicitly datetime, so:

select distinct bnd_ser_nbr, trans_nbr, uws_product_cd, bill_id, cast(null datetime) pol_eff_dt, cast(null datetime) pol_exp_dt er_ro_urs_prem_detail urs_prem_detail_interim

demo here. in demo, if alter type 2 columns cast to, , seek assign datetime value, conversion error.

sql tsql datetime select select-into

No comments:

Post a Comment