上一页 1 ··· 3 4 5 6 7
摘要: 测试数据: create table test(value int not null) -----drop table test insert into test (value)select 2union allselect 3union allselect 2union allselect 7union allselect 6union allselect 3union allselect... 阅读全文
posted @ 2013-04-02 11:37 忙碌在路上 阅读(1537) 评论(0) 推荐(0)
摘要: 带any嵌套查询 select emp.empno,emp.ename,emp.sal from scott.emp where sal>any(select sal from scott.emp where job='manager'); 等价于 select sal from scott.emp where job='manager' 结果为 sal:2975 2850 245... 阅读全文
posted @ 2013-03-13 10:04 忙碌在路上 阅读(334) 评论(0) 推荐(0)
摘要: SELECT case when not exists(SELECT Cons_Date FROM sbcHisMaster WHERE HisTypeNO='L' AND ProductSN ='M7D2028') THEN (SELECT Cons_Date FROM sbcHisMaster WHERE HisTypeNO='Y' AND ProductSN ='... 阅读全文
posted @ 2013-03-13 09:38 忙碌在路上 阅读(1045) 评论(0) 推荐(0)
摘要: create table employee (empid int ,deptid int ,salary decimal(10,2)) insert into employee values(1,10,5500.00) insert into employee values(2,10,4500.00) insert into employee values(3,20,1900.00... 阅读全文
posted @ 2013-01-10 11:36 忙碌在路上 阅读(302) 评论(0) 推荐(0)
摘要: --得到数据库中所有用户表 Select [name] from sysObjects Where xtype='U'and [name]<>'dtproperties' Order By [name] --得到数据库中所有用户视图 Select [name] From sysObjects Where xtype='V' And [name]<>'syssegments' And... 阅读全文
posted @ 2012-12-20 14:22 忙碌在路上 阅读(760) 评论(0) 推荐(0)
摘要: select c_gcode,c_barcode,c_name,c_price_disc,c_price,c_status from tb_gds where ( c_price like '%._[1,2,3,4,5,6,7,8,9]%' or c_price_disc like '%._[1,2,3,4,5,6,7,8,9]%' )and c_weigh='否' and c_stat... 阅读全文
posted @ 2012-12-12 09:45 忙碌在路上 阅读(2234) 评论(0) 推荐(0)
摘要: 使用 RAISERROR 与 PRINT 相比,RAISERROR 在把消息返回给应用程序方面的功能更强大。RAISERROR 能以下列方式中的任意一种返回消息: 已通过 sp_addmessage 系统存储过程添加到 master.dbo.sysmessages 上的由用户定义的错误信息。 在 RAISERROR 语句中指定的消息字符串。 RAISERROR 也有 PRI... 阅读全文
posted @ 2012-10-07 09:05 忙碌在路上 阅读(272) 评论(0) 推荐(0)
摘要: declare @name varchar(8000) declare cursor_a cursor for select name from sysobjects where xtype='U' open cursor_a fetch next from cursor_a into @name while @@fetch_status=0 begin e... 阅读全文
posted @ 2012-09-29 15:51 忙碌在路上 阅读(250) 评论(0) 推荐(0)
摘要: len 主要计算的是字符数量,比如’aabbc’是6个字符,那么’钓鱼岛是中国的’是7个字符,么’钓鱼岛是中国的aabbcc’就是13个字符, 而datalength主要计算的是字节数,注意是字节,一个汉字是2个字节哦,字母是1个字节哦,那么’钓鱼岛是中国的’就是14个字节了,对吧,’钓鱼岛是中国的aabbcc’就是14字节加6字节等于20字节了。 阅读全文
posted @ 2012-09-27 10:28 忙碌在路上 阅读(192) 评论(0) 推荐(0)
摘要: drop table tb create table tb(时间 datetime , 金额 int) insert into tb values('2007-1-1 10:00:23' , 8 ) insert into tb values('2007-1-1 10:01:24' , 4 ) insert into tb values('2... 阅读全文
posted @ 2012-08-20 08:31 忙碌在路上 阅读(211) 评论(0) 推荐(0)
摘要: 我现有一表名为: product1,字段内容如下: productID productName price num 101 商品1 2.15 2 112 商品2 5.5 5 203 商品3 4.15 8 101 商品1 2.15 5 一个表为product2,字段内容如下... 阅读全文
posted @ 2012-05-23 15:34 忙碌在路上 阅读(1099) 评论(0) 推荐(0)
摘要: SQL Server FOR XML PATH 语句的应用 经常在论坛看到高手使用了 for xml path,由于是搜索一下,记录了详细的使用方法。 在SQL Server中利用 FOR XML PATH 语句能够把查询的数据生成XML数据,下面是它的一些应用示例。 DECLARE @TempTable table(UserID int , UserName nvarchar(5... 阅读全文
posted @ 2012-04-21 17:24 忙碌在路上 阅读(2761) 评论(0) 推荐(1)
摘要: //简单计算 2个时间 相差的 天数 和 小时数 declare @time1 datetime declare @time2 datetime set @time1='2012-03-19' set @time2=GETDATE() select LTRIM(DATEDIFF(dd,@time1,@time2))+'天'+LTRIM(DATEDIFF(hh,@ti... 阅读全文
posted @ 2012-04-18 16:22 忙碌在路上 阅读(369) 评论(0) 推荐(0)
摘要: 如果表中没有很好的列 来确定 唯一行,不防用一下这个 方法 还是比较精准的 update db set a=11111 from (select row_number() over ( order by a) as id ,a from #b) as db where id=2 阅读全文
posted @ 2012-04-09 13:39 忙碌在路上 阅读(439) 评论(0) 推荐(0)
摘要: select b as 标识,COUNT(*) AS 数量,(select COUNT(*) from num) as 总数量,(ltrim(cast(count(*)*100./nullif((select count(*) from num),0) as decimal(12,2)))+'%') as 占比 from num group by b order by 数量 阅读全文
posted @ 2012-04-07 15:34 忙碌在路上 阅读(993) 评论(0) 推荐(0)
摘要: 系统函数用于获取有关计算机系统、用户、数据库和数据库对象的信息。系统函数可以让用户在得到信息后,使用条件语句,根据返回的信息进行不同的操作。与其它函数一样,可以在SELECT 语句的SELECT 和WHERE 子句以及表达式中使用系统函数。 ·COL_LENGTH() COL_LENGTH() 函数语法如下: COL_LENGTH (<'table_name'>, <'colum... 阅读全文
posted @ 2012-03-09 14:27 忙碌在路上 阅读(314) 评论(0) 推荐(0)
摘要: SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition') ----或者 select @@VERSION 阅读全文
posted @ 2012-02-24 11:45 忙碌在路上 阅读(294) 评论(0) 推荐(0)
摘要: 表 pdzb2 已经建立了。~~~~~~~~~~~~~~ -----------------------------------华丽的分割线------------------------------------------- ----声明需要的变量 declare @sql varchar(2000), @TypeID int, @gys... 阅读全文
posted @ 2011-12-25 13:24 忙碌在路上 阅读(353) 评论(0) 推荐(0)
摘要: ---切入数据库 USE zhangbei ----自定义函数定义 create function perimeter (@S numeric(38,20)) returns numeric(38,20) as begin declare @pi numeric(38,20) set @pi = '3.1415' return (select ... 阅读全文
posted @ 2011-12-14 10:16 忙碌在路上 阅读(525) 评论(0) 推荐(0)
摘要: 今天在群里看到有人提问 怎么实现如下图的功能,很明显,如果我们手工插的话,费时费力,那何不来个循环判断插入了,这使我想起了 while 语句 说做就做 于是 写出了 下面的代码: create table rq (dt datetime , wb varchar(5) ) declare @dt datetime declare @n ... 阅读全文
posted @ 2011-12-11 14:28 忙碌在路上 阅读(1256) 评论(0) 推荐(0)
摘要: 功能键-输入plu号-确认-两次去皮键-输入新价格-确认 ok 阅读全文
posted @ 2011-11-15 13:37 忙碌在路上 阅读(3521) 评论(0) 推荐(0)
摘要: SQL学习之查询技巧 查询表是否存在的两种方法方法一 判断系统对象是否存在DECLARE @DbTableFileName VARCHAR(100)SET @DbTableFileName = 'tx'IF objectproperty(object_id(@DbTableFileName),'IsUserTable') IS NOT NULL PRINT 'EXISTS 'ELSE PRINT 'NOT EXISTS 'IF object_id(@DbTableFileName) IS NOT NULL PRINT 'E 阅读全文
posted @ 2011-10-28 16:39 忙碌在路上 阅读(3333) 评论(0) 推荐(1)
摘要: 1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1 要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。示例如下:INSERT INTO SELECT语句复制表数据 --1.创建测试表 create TABLE Table1 ( a varchar(10), b varchar(10), ... 阅读全文
posted @ 2011-10-26 20:03 忙碌在路上 阅读(72094) 评论(4) 推荐(10)
摘要: Sql ISNULL() 函数 使用指定的替换值替换 NULL。语法ISNULL ( check_expression , replacement_value ) 参数check_expression将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。replacement_value在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。返回类型返回与 check_expression 相同的类型。注释如果 check_expression 不为 NU 阅读全文
posted @ 2011-10-18 10:57 忙碌在路上 阅读(7068) 评论(0) 推荐(1)
摘要: 创建表:create table userinfo(username varchar(10) not null,sex varchar(2) not null,age tinyint )insert into userinfo (username,sex,age)values ('张贝','男',22)insert into userinfo (username,sex,age)values ('张成伟','男',24)insert into userinfo (username,sex)values ('栗东岳' 阅读全文
posted @ 2011-10-18 10:46 忙碌在路上 阅读(949) 评论(0) 推荐(0)
摘要: bcp命令是SQL2005 一个实用的数据导出导入工具,我们可以运用这个命令方便的到处导入数据 首先我们欣赏一下bcp命令的 格式: BCP是SQL Server中负责导入导出数据的一个命令行工具,它是基于DB-Library的,并且能以并行的方式高效地导入导出大批量的数据 BCP除了可以在控制台执行外,还可以通过调用SQL Server的一个系统存储过程xp_cmdshell以SQL语句的方式运行BCP。如:EXEC master..xp_cmdshell 'BCP NTS.dbo.T_User out c:\User.txt -c -U"sa" -P"password"' 1. 四个动作 01. 导入:这个动作使用IN命令完成,后面跟需要导入的文件名 02. 导出:这个动作使用OUT命令完成,后面跟需要导出的文件名,数据源是表或者视图 03. 使用SQL语句导出:这个动作使用QueryOut命令完成,跟OUT类似,数据源是SQL语句 阅读全文
posted @ 2011-10-15 11:43 忙碌在路上 阅读(4745) 评论(0) 推荐(1)
摘要: 很多朋友在装SQL2005的时候,都会遇到com+目录要求不符合安装条件,这是我们需要启动两个服务,第一个是 com+ system application 服务,第二个 是 Distributed Transaction Coordinator服务,但是我们在启动 Distributed Transaction Coordinator服务的时候,会报个1068错误,这是因为安装SQL安装的时候,需要安装个帮助文件,但由于系统编码问题,造成无法写入注册表,这个时候,我们修改注册表就可以了,具体做法为:开始-运行—输入 regedit 打开我们可爱的注册表,展开找到 阅读全文
posted @ 2011-09-26 10:55 忙碌在路上 阅读(1992) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7