SQL 的一些基本操作
在一张表里取每种类型的记录N条的SQL语句。
SELECT * FROM tabelname AS a WHERE a.id in(select top N from tabelname where id=a.id order by id) ORDER BY [id];
插入一表中列到另一个表
-------------
insert into test(image)
SELECT
biglb.bigimages
FROM biglb
复制一表中列到另一个表(两个表中记录数、类型一样)
---------------*********************-----------------
在sql中,如果想将表t1字段d1的值全部复制到表t2字段d2下
(d1和d2的记录数、类型一样)
update t2 set a.d2=b.d1 from t2 as a,t1 as b
--------------------------------------------------------------------------
int iResult;
iResult = ds.E...("select top 30 *
from table1 where weizhi> 0")
if(iResult<30)
{
ds.E....("select * from table1 where ... union select top
(30 - iResult) * from table2 where...");
}
SqlConnection sql = new
SqlDataAdapter objAdapter = new
SqlDataAdapter();
objAdapter.TableMappings.Add("Table",
CustomerData.ACCEPTER_TABLE);
SqlCommand objCommand = new
SqlCommand("select * from t1 where weizhi > 0 ",
Pro_GetSqlConnect);
DataSet ds = new DataSet();
objAdapter.SelectCommand = objCommand;
objAdapter.Fill(ds);
return ds;
DataRowCollection rows
= ds.Tables["t1"].Rows;
insert into x3(xid, name, gdate,weizhi)
select a.id
, a.name, a.gdate , a.weizhi from x1 as a where a.weizhi > 0 union select top
27 a.id,a.name,a.gdate,a.weizhi from x2 as a order by a.gdate
desc
浙公网安备 33010602011771号