sql - Check Missing data when id is not null or blank -
i trying check if data present id not corresponding value entire row discard output. if both value , id blank ok, , row retain in output
declare @tab table ( id varchar (50), sku varchar (50), resistor_id1 varchar (50), resistor_value varchar (50), capacitor_id varchar (50), capacitor_value varchar (50), inductor_id varchar (50), inductor_value varchar (50) ) insert @tab select '1', 'bpn1256', '1033', '' , 'rma56', 'ceramic', 'pvan59', 'ferrite' union select '1', 'san9286', '' , '' , 'tma56', 'film' , '' , '' union select '1', 'rja1896', '3033', '35ohm', 'uma56', 'ceramic', 'pvan59', 'ferrite' union select '1', 'dnn5256', '4033', '45ohm', 'qma56', '' , 'pvan59', 'ferrite' union select '1', 'lxa6556', '5033', '65ohm', 'zma56', 'film' , 'pvan59', ''
expected output
1 san9286 tma56 film 1 rja1896 3033 35ohm uma56 ceramic pvan59 ferrite
please share expertise. thanks
well, why not directly? need rows when both id , value blank, or when both id , value not blank. put clause, repeat 3 id-value pairs, , you're done.
select * @tab (resistor_id1 != '' , resistor_value != '' or resistor_id1 = '' , resistor_value = '') , (capacitor_id != '' , capacitor_value != '' or capacitor_id = '' , capacitor_value = '') , (inductor_id != '' , inductor_value != '' or inductor_id = '' , inductor_value = '')
important note: didn't specify dbms, might need alter query syntax. example, in oracle blank string(''
) treated null
value , should checked value null
instead of value = ''
. in mysql, null , empty string different things, , should checked differently.
upd: should work fine using =
, !=
ms sql server, if inserted blank strings , not nulls. if you're not sure, might want take @ how check if sql server string null or empty
Comments
Post a Comment