Skip to main content
2 of 14
Format
McNets
  • 23.9k
  • 11
  • 50
  • 89

How to declared integer in where condition using dynamic sql?

I tried with 1,2 and 3 quotes but I am getting Conversion failed when converting the varchar value '

I also tried year(s_tran_d) with /without conversion. Can someone please help me how to use declared integer in where condition.

inner join focis.focis.PITM'+@Datemm_yyyy+' pitm 
    on nep.s_pitm_c=pitm.pitm_c
    and  cast(year(s_tran_d) as nchar)='''+@yyyy+''' 
    and cast(month(s_tran_d) as nchar) ='''+@mm+'''

inner join focis.focis.PITM'+@Datemm_yyyy1+' pitm1 
    on nep.s_pitm_c=pitm1.pitm_c
    and cast(year(dateadd(m,-1,s_tran_d)) as nchar) =''+ @yyyy1 +'' 
    and cast(month(s_tran_d)-1 as nchar)= '''+@mm1 +'''

Thank you Ramu

Ramu
  • 13
  • 2