
sql
pmandy
这个作者很懒,什么都没留下…
展开
-
关于日期操作
1:获得指定日期指定月份的第一天formular form:dateadd(month,datediff(month,'19000101',orderdate),'19000101')select distinct dateadd(month,datediff(month,'19000101',orderdate),'19000101')from sales.ordervalues...2010-07-14 17:30:42 · 97 阅读 · 0 评论 -
sql分页存储过程(返回记录数)
if里面处理的是带搜索条件的else里面处理的是不带搜索条件的-- ================================================SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-...原创 2013-03-06 14:39:24 · 186 阅读 · 0 评论 -
一段TSQL脚本,自用
USE [WMDRM]GO/****** 对象: Index [unique_keyvalue] 脚本日期: 11/20/2012 11:26:42 ******/IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Key]') AND name = N'unique_keyval...原创 2012-11-20 11:29:16 · 112 阅读 · 0 评论 -
SQL数据库中订单号相同,取日期最大值的记录问题(类似问题的解决方法)
在商品申请表中有很多条记录,只是主键和记录的状态和创建时间不同,如何根据ProductId和CoursewareId,找出日期最近的相关记录SELECT * FROM dbo.E_ProductApplication AS t1WHERE CreateDate IN( SELECT MAX(CreateDate) FROM dbo.E_ProductAppl...原创 2013-05-10 09:46:45 · 1825 阅读 · 0 评论 -
Red Gate系列之三 SQL Server 开发利器 SQL Prompt 5.3.4.1 Edition T-SQL智能感知分析器 完全破解+使用教程...
博客园文章:http://www.cnblogs.com/VAllen/archive/2012/09/08/SQLPrompt.html原创 2013-01-05 12:20:01 · 120 阅读 · 0 评论 -
SCOPE_IDENTITY和@@IDENTITY的用法
SCOPE_IDENTITY和@@IDENTITY的用法SCOPE_IDENTITY和@@IDENTITY的用法SCOPE_IDENTITY返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。一个作用域就是一个模块——存储过程、触发器、函数或批处理。因此,如果两个语句处于同一个存储过程、函数或批处理中,则它们位于相同的作用域中。语法SCOPE_...原创 2013-12-07 16:39:20 · 120 阅读 · 0 评论 -
如何不打断Sql脚本直接复制到C#代码中
通常把数据库中的大段代码复制到C#代码中,格式都会有问题,可以这样解决: strSql = string.Format(@"SELECT TOP {0} [ApplicationId] , [StatusId] , ...原创 2013-02-22 12:13:28 · 122 阅读 · 0 评论 -
with公用表表达式
语法如下: WITH a AS(SELECT TOP 1000 [ProductEvaluationId] ,[OrderDetailId] ,[UserId] ,[Contents] ,[Score] ,[StatusId] ,[CreateUserId] ,[CreateDat...原创 2013-02-25 11:00:25 · 404 阅读 · 0 评论 -
按月分类统计
select case when AudioType=1 then '硬广' when audiotype=21 then '台标' when audiotype=22 then '片花' when audiotype=23 then '报时' end as AudioType,isnull(isnull(co...原创 2014-07-03 13:23:50 · 220 阅读 · 0 评论 -
top 100 percent
有时候我们需要用到top,但是我们又却是不需要指定特定的值,比如由于我们用了order by,就必须用top了,问题怎么解决呢,用top 100 percent即刻,这样做就是去除所有的,这样完全是为了满足语法上的要求!...原创 2013-03-01 18:16:54 · 185 阅读 · 0 评论 -
sqlserver 变量拼接
string cmd = "update [Tlb_VODContentServer] set BaseUrl='" + cs.BaseUrl + "',CurrentLoading='" + cs.CurrentLoading + "',IsAvailable='" + cs.IsAvailable + "',DiskFreeSpaceInByte='" + cs.DiskFreeSp...原创 2012-06-01 10:06:38 · 608 阅读 · 0 评论 -
多变量对应多字段赋值 select对多个变量赋值
如果有多条记录,则获得最后一个:SQL codecreate table tablea(id int,ip varchar(15),apps varchar(10))insert into tablea select 23,'127.0.0.1','aaa'insert into tablea select 23,'127.0.0.2','abb'godeclare @Va...原创 2012-05-23 10:52:13 · 786 阅读 · 0 评论 -
再说分页
数据库中有这样一张表,包含1000000条数据,数据字段如下:Gid,title,fariqi,neibuyonghu,reader现对其进行分页。--create clustered index myIndex on dbo.TGongwen(fariqi,gid);--drop index dbo.TGongwen.myIndex;declare @pagesize as int...2010-07-15 09:56:00 · 88 阅读 · 0 评论 -
TSQl逻辑处理顺序
listing 1-1 logical query processing step numbers (5) select (5-2) distinct(5-3) top(<top_specification>)(5-1)<select_list>(1) from (1-j) <left_table> <join_type>...2010-07-16 14:09:29 · 106 阅读 · 0 评论 -
grouping by week(按周统计数据)
select orderdate-weeknum+1 as week_start, orderdate-weeknum+7 as week_end, count(*) as ordernumfrom ( select datepart(weekday,orderdate+@@datefirst-1) as weeknum,orderdate ...原创 2010-07-26 10:21:18 · 205 阅读 · 0 评论 -
超经典的多条件查询
solution 1 the drawback is performance is slow use testdb;gocreate proc dbo.usp_GetOrders@OrderID as int=null,@CustomerID as nchar(5)=null,@EmployeeID as int=null,@OrderDate as Da...2010-07-29 14:56:28 · 122 阅读 · 0 评论 -
动态sql详谈动态指定表名 列名(exec sql_executesql)
--在动态sql中,无论exec还是exec sp_executesql,都不允许使用参数形式的表名和列名,--你可以使用变量或者在存储过程中使用存储过程参数声明部分的参数,而不是直接使用--exec sp_executesql参数声明部分的参数--典型的错误代码(there is no wrong with grammer,but not any row is returned)declar...2010-07-30 14:53:49 · 1130 阅读 · 0 评论 -
sql变量拼接解惑
---这篇文章仅是对自己的一个提醒 写的比较凌乱 declare @s datetimedeclare @e datetimedeclare @n varchar(10)set @s = convert(datetime,'2006-12-01')set @e = convert(datetime,'2007-09-09')set @n = 'm'select * from sales....2010-11-16 15:39:37 · 206 阅读 · 0 评论 -
动态sql 无变量的简单例子
作用是在指定的表中,查找指定的列(主键和描述,用作dropdownlist等控件的数据源),其实就是将表明和列明参数化USE [TKInfDB]GO/****** Object: StoredProcedure [MSG].[P_GetAllClasses] Script Date: 05/22/2012 11:51:47 ******/SET ANSI_NULLS O...2012-05-22 11:57:40 · 121 阅读 · 0 评论 -
动态sql 传递多参 多变量的例子
在分类表中插入一条新的记录,主键是取到当前的最大值+1USE [TKInfDB]GO/****** Object: StoredProcedure [MSG].[P_CreateNewClass] Script Date: 05/22/2012 12:00:13 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ON...2012-05-22 12:01:49 · 304 阅读 · 0 评论 -
SQL Server数据库大型应用解决方案总结
[url]http://tech.it168.com/a2012/0110/1300/000001300144.shtml[/url]非常不错的文章。原创 2014-04-02 16:17:39 · 110 阅读 · 0 评论