select * from tableA
select * from tableB我要第二个集的另外,谁能帮我改正
set @sqlTmp='select @a=count(id) from tableA like '%xxx%''
这个错误的语句意思是想用@a得到这个表的行数,因为有 like 我不知道如何不拼sql,并以exec执行的方法

解决方案 »

  1.   

       String ConnString  = "";
       using(SqlConnection Connection = new SqlConnection(myConnString))
       {
       SqlCommand Command = new SqlCommand();
       SqlDataReader reader ;
       Command.CommandType = CommandType.StoredProcedure;
       Command.Connection = Connection;
       Command.CommandText = "";
       int RecordCount=0; 
       try
       {
        Connection.Open();
        reader = command.ExecuteReader();
        int RecordCount=0; 
        while (reader.Read()) 
        {
         
        }
        reader.NextResult();
        RecordCount = 0;
        while (reader.Read()) 
        {
         RecordCount = RecordCount + 1;
        }
       }
       catch (Exception ex)
       {
       }
       finally
       {
        Connection.Close();
       }
     }
    declare @a int, 
    @sql nvarchar(4000),@b nvarchar(20)set @sql='select @a=count(*) from tableName where name like  ''%'+@b+'%'''
    exec sp_executesql @sqls,N'@a int output',@a output 
    select @a