随笔分类 -  T-Sql

摘要:1.在数据库中查询出要删除的记录的关键字段 select col1,col2,col3,col4 from tabName; 2.将结果 copy 到 excel 中 3.在 excel 的 E1 单元格写如下内容="delete fromtabName where col1='"&A2&"' andcol2 ='"&B2&"' and col3='"&C2&"' and col4='"&D2&& 阅读全文
posted @ 2012-11-16 11:37 草青工作室 阅读(1104) 评论(0) 推荐(2)
摘要:select CONVERT(varchar, getdate(), 120 )2004-09-12 11:06:08select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')20040912110608select CONVERT(varchar(12) , getdate(), 111 )2004/09/12select CONVERT(varchar(12) , getdate 阅读全文
posted @ 2012-10-23 10:40 草青工作室 阅读(144) 评论(0) 推荐(0)
摘要:我这个是按照时间求最大的例子select a.*frommyTab a,( select Id,MAX(EndTime ) EndTime from myTab group by Id)bwhere a.Id = b.Id anda.EndTime = b.EndTime;注:如果遇到同id 下endtime 字段值一样的记录可能就这个就不好使了 ,抛砖引玉一下吧~~~ 阅读全文
posted @ 2012-09-07 15:20 草青工作室 阅读(140) 评论(0) 推荐(0)
摘要:-- 查找所有父节点with tab as(select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=316--子节点union allselect b.Type_Id,b.ParentId,b.Type_Name from tab a,--子节点数据集 Sys_ParamType_V2_0 b --父节点数据集where a.ParentId=b.Type_Id --子节点数据集.parendID=父节点数据集.ID)select * from tab;-- 查找所有子节点with tab as(selec 阅读全文
posted @ 2012-08-15 15:14 草青工作室 阅读(278) 评论(1) 推荐(0)
摘要:写程序是总是用到父子关系的数据,通过给定节点得到其子节点的记录,写视图但是不支持传入参数。那就用 自定义函数来完成这个需求吧!1.创建视图create Function myFunc(@id Int)Returns @tab table (id int,ParentId int,[Level] int,TName nvarchar(50))Asbegin --DECLARE @typeId int; --set @typeId =6;with cte as( select * from tab where id= @id union all select a.* from tab a, ct. 阅读全文
posted @ 2012-06-13 22:01 草青工作室 阅读(174) 评论(0) 推荐(0)
摘要:1.创建函数脚本SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:-- Create date:-- Description:替换字段中的HTML标签标签内的属性,保留标签对包含的内容-- =============================================CREATE FUNCTION ReplaceHTML(@source nvarchar(4000) --原字符串)RETURNS nvarchar(4000)AS 阅读全文
posted @ 2012-06-12 11:13 草青工作室 阅读(156) 评论(0) 推荐(0)
摘要:/*过程功能:分页创建时间:12-06-09修改时间:130115,支持多个字段排序分页*/--CREATE PROCEDURE up_paginationALTER PROCEDURE [dbo].[up_pagination](@tblName nvarchar(200), ----要显示的表或多个表的连接@fldName nvarchar(500) = '*', ----要显示的字段列表@pageSize int = 1, ----每页显示的记录个数@page int = 10, ----要显示那一页的记录@fldSort nvarcha... 阅读全文
posted @ 2012-06-09 20:09 草青工作室 阅读(133) 评论(0) 推荐(0)
摘要:sp_executesql 过程与 exec 关键字区别sp_executesql 可以在动态 sql 中使用变量,并且将变量输出exec 则只能执行动态 sql 和 存储过程(执行过程不需要加小括号,执行动态 sql 则必须加小括号)----------------------------------------------------------------------------------declare @count intdeclare @sql1 nvarchar(100)declare @sql2 nvarchar(100)declare @str nvarchar(10)--1 阅读全文
posted @ 2012-06-09 18:58 草青工作室 阅读(383) 评论(0) 推荐(0)