随笔分类 - SqlServer
SqlServer
摘要:将以下代码中的TABLE_NAME替换成所需表名称即可。 注意 declare 和set 语句后面不要有 ;否则可能执行不成功 declare @S_Column varchar(8000)set @S_Column =(SELECT column_name ca FROM INFORMATION_
阅读全文
摘要:;with cte as ( select CONVERT(DATE, DATEADD(DAY, -9, GETDATE())) as paytime union all select dateadd(day,1,paytime) from cte where paytime<GETDA...
阅读全文
摘要:游标实例:Declare MyCusror Cursor ScrollFor Select * From Master_Goods Order By GoodsIDOpen MyCursorFetch next From MyCursor Into @GoodsCode,@GoodsNameWhil...
阅读全文
摘要:某公司内部的sp模板create procedure [usp_my_procedure_name]asbegin set nocount on; declare @trancount int; set @trancount = @@trancount; begin try ...
阅读全文
摘要:create procedure [spname]([spvariable])asbeginbegin transactionbegin try--具体sql过程commit;end trybegin catchrollback;end catchend
阅读全文
摘要:企业库6的DAAB使用方法变了参考一篇文章Database provider factory not set for the static DatabaseFactory18. August 2013 Anil Asp.Net , C# , Enterprise Library Comment...
阅读全文
摘要:SQLServer 2005-2008-2012使用Oracle时,默认是手动提交。而SQLServer2005中,默认是自动提交,但是SQLServer支持配置。 方法:用SSMS连接到SQL Server菜单栏工具 –> 选项选择查询执行 –> SQL Server –> ANSI确认选择了SET IMPLICIT_TRANSACTIONS点击OK按钮
阅读全文
摘要:SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算详细如下use tempdb go if (object_id ('t1' ) is not null ) drop table t1 if (object_id ('t2' ) is not null ) drop table t2 go create table t1 (a int ) insert into t1 select 1 union select 2 union select 3 create table t2 (a int ) ins
阅读全文
摘要:select S_ID,P_ID,P_Url,Users from (select S_ID,P_ID,P_Url from T_Test) A outer apply--右加字段给主表(select Users =Replace(Replace((select U_User a from R_Te...
阅读全文
摘要:select top 1 * from T_ClassSecond order by NEWID()使用 top 来获取最多多少条,使用 order by NewID()随机排序
阅读全文
摘要:其实很简单,利用表的不同别名,数据库为认为是两个不同的表,然后分别统计。数量大,会比较慢select zgcj,--分组项 COUNT(1) cou,--分项统计, (select COUNT(1) from CJ_ZGT b where b.zgcj>=a.zgcj and b...
阅读全文

浙公网安备 33010602011771号