sql - Check string starts with specific letter -
please me below query , want check if string starts 'g' or 'f' in condition along existing condition. here query
first query :-
select top 1 lc_id, isnull(lc_ud, 0) record contract lc_id = 'f01'
output
f01 | 1 ( if available) else no record return.
second query:
if lc_id starts 'f%' or 'g%'
how can integrate both query 1 if there no record available 'f01' value, check if lc_id starts f & g return output
f04 | 1
else no record return.
you want prioritize values being returned. because want one, can order by
:
select top 1 lc_id, coalesce(lc_ud, 0) record contract lc_id '[fg]%' order (case when lc_id = 'f01' 1 else 2 end);
note: assumes using sql server (based on syntax).
Comments
Post a Comment