改成这样exec('Select TOP' + str(@getNum) + 'T_Property.*,T_NewsContent.* from T_Property,T_NewsContent where T_NewsContent.I_ColumnID = T_Property.I_ID and T_Property.I_ParentID ='+ str(@columnID))

解决方案 »

  1.   

    楼上正解,sql里拼接字符串是这样的,也可以用这种(需要转换的类型先用cast):
    'Select TOP''' +@getNum+ '''T_
      

  2.   

    在补充下 TOP' top的后面应该加一个空格 同理'T_Property 前也要加个空格
    不然传值过来就会成为 select top7T_Property 这样一定报错
      

  3.   

    exec('Select TOP ' + str(@getNum) + ' T_Property.*,T_NewsContent.* from T_Property,T_NewsContent where T_NewsContent.I_ColumnID = T_Property.I_ID and T_Property.I_ParentID ='+ str(@columnID))