当前位置: 代码迷 >> PB >> sql语句总使用in后面的变量怎么写
  详细解决方案

sql语句总使用in后面的变量怎么写

热度:84   发布时间:2016-04-29 09:21:53.0
sql语句总使用in后面的变量如何写?
string ls_dq_string
int li_dsj_cnt

ls_dq_string= '35城市组'+','+'杭州'

SELECT count(1) Into :li_dsj_cnt1 From t_hlcm_dsj_lsb Where dq in (:ls_dq_string) ;

SELECT count(1) Into :li_dsj_cnt2 From t_hlcm_dsj_lsb Where dq in ('35城市组','杭州') ;

请教:为甚第一条语句没有数据返回?而第二条语句的是有数据返回的,li_dsj_cnt2>0的,这样的in语句里面的变量该如何写?求助


ls_dq_string= "'35城市组'"+','+"'杭州'"

messagebox("ls_dq_string",ls_dq_string) --结果为: '35城市组','杭州'

ls_sql="SELECT count(1) Into :li_dsj_cnt From t_hlcm_dsj_lsb Where dq in"+ '('+ls_dq_string+')'

messagebox("ls_sql",string(ls_sql ))


结果是:SELECT count(1) From t_hlcm_dsj_lsb Where dq in('35城市组','杭州')
居然也不行



------解决方案--------------------
SELECT count(1) Into :li_dsj_cnt1 From t_hlcm_dsj_lsb Where dq in (:ls_dq_string) ;

-->

SELECT count(1) Into :li_dsj_cnt1 From t_hlcm_dsj_lsb Where charindex(dq , :ls_dq_string) > 0 ;

------解决方案--------------------
怎么不早说
那就用datawindow的retrieve带个数组参数。

或者 


DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;
int li_dsj_cnt1
string sqlstatement
ls_dq_string= "'35城市组','杭州'"
sqlstatement = "SELECT count(1) From t_hlcm_dsj_lsb Where dq in ("+ls_dq_string+")"
PREPARE SQLSA FROM :sqlstatement ;
OPEN DYNAMIC my_cursor ;
FETCH my_cursor INTO :li_dsj_cnt1;

CLOSE my_cursor ;
  相关解决方案