3、当前数据库中,将表A插入到表B
insert into a (a的字段 ) select * form b
a的字段与*字段要一致
4、将List 以 指定字符 连接成一个字符串 如 1、2、 3
List<string> list = new List<string>();
var str = list.Aggregate((p, next) => (p + "-" + next));
5、将某个字段 转成对应的类型
cast( unit.PK_EntID as nvarchar(50)) PK_EntID
6、存储过程分页
USE 数据库名
GO
/****** Object: StoredProcedure [dbo].[fw_PageProcedure] Script Date: 12/29/2015 10:18:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--计算所有的记录条数 并返回
declare @@sqlCount nvarchar(max)
set @@sqlCount=N' select @outRecordCount=COUNT(*) '+N' from '+ @afterFromBeforeOrderBySqlString
exec sp_executesql @@sqlCount , N'@outRecordCount int output' , @outRecordCount output
--定义指定页需要查看的记录条数
if @pageIndex<=1 --优化第一页的查询,直接获得前@pageSize条记录
begin
set @pageIndex=1
-- exec(' select top '+@pageSize+' '+@searchField+'
--from '+@afterFromBeforeOrderBySqlString+'
--order by '+@orderByField)
declare @@sql varchar(max)
set @@sql= ' select top '+ltrim
(@pageSize)+' '+@searchField+'
from '+@afterFromBeforeOrderBySqlString+'
order by '+@orderByField
exec(@@sql)
print @@sql
end
else
begin
declare @@PageCount bigint
declare @@IndexFrom bigint
declare @@IndexTo bigint
set @@PageCount=@outRecordCount/@pageSize
if(@outRecordCount%@pageSize>0)
begin
set @@PageCount=@@PageCount+1
end
if(@pageIndex>=@@PageCount)
begin
set @pageIndex=@@PageCount
set @@IndexFrom=(@pageIndex-1)*@pageSize+1
set @@IndexTo =@outRecordCount
end
else
begin
set @@IndexFrom=(@pageIndex-1)*@pageSize+1
set @@IndexTo =@pageIndex*@pageSize
end
exec(' select
*
from
(select
ROW_NUMBER() OVER(ORDER BY '+@orderByField+' ) PageProcedureRowNumber,'+@searchField+'
from
'+@afterFromBeforeOrderBySqlString+') PageProcedureTable
where
PageProcedureTable.PageProcedureRowNumber between '+@@IndexFrom+' and '+@@IndexTo)
end
set @outPageSize=@pageSize
set @outPageIndex=@pageIndex
6、 将日期的年月提取出来,进行处理
select place,count(*) Value ,CONVERT(VARCHAR(7),happenTime,120) YearAndMonth from T_Dat_UnexpectedEvent unex
where place is not null
and happenTime between '2009-04-23 09:15:00.000' and '2015-12-23 00:00:00.000'
and place in(1,2)
group by place, CONVERT(VARCHAR(7),happenTime,120)
order by CONVERT(VARCHAR(7),happenTime,120)