t_bm:表,geocode:编码字段,ls_code:变量,li_jb:变量,根据输入值ls_code、li_jb作为条件查询编码字段某几位的最大值,如下:
select IsNull(Max(left(geocode,li_jb*2))) from t_bm where left(geocode,(li_jb-1)*2)=left(ls_code,(li_jb-1)*2)
select IsNull(Max(left(geocode,li_jb*2))) from t_bm where left(geocode,(li_jb-1)*2)=left(ls_code,(li_jb-1)*2)
谢谢大家!
结贴!