SQL查询每行中最大值的技巧
--------------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-04-23 08:08:36
-- Version:Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
-- Blog : http://blog.csdn.net/htl258
-- Subject: SQL查询每行中最大值的技巧
--------------------------------------------------------------------------
--> 生成测试数据表:tb
IF NOT OBJECT_ID('[tb]') IS NULL
DROP TABLE [tb]
GO
CREATE TABLE [tb](
a SMALLINT,
b SMALLINT,
c SMALLINT,
d SMALLINT,
e SMALLINT,
f SMALLINT,
g SMALLINT
)
INSERT [tb]
SELECT 1,2,3,4,5,2,3 UNION ALL
SELECT 4,5,6,7,7,2,0 UNION ALL
SELECT 4,9,6,7,7,9,6
GO
--SELECT * from [tb]
-->SQL查询如下:
SELECT *,
(SELECT MAX(a)
from(
SELECT a UNION ALL
SELECT b UNION ALL
SELECT c UNION ALL
SELECT d UNION ALL
SELECT e UNION ALL
SELECT f UNION ALL
SELECT g
) AS t
) AS maxvalue
from tb
/*
a b c d e f g maxvalue
------ ------ ------ ------ ------ ------ ------ --------
相关文档:
注释:只适合单表单列数据,
create database test
go
use test
go
create table users
(
:id int identity(1,1) primary key not null,
:name nvarchar(20)
)
go
create proc sp_Inserts
@Names nvarchar(4000)
as
declare @Name nvarchar(20),@ErrorSum int
:set @ErrorSum = 0
:begin tra ......
使用 CONVERT:
CONVERT (data_type[(length)], expression [, style])
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),\'-\',\'\'),\' \',\'\'),\':\',\'\')
20040912110608
select CONVERT(varchar(12) , getdate(), 111 ) ......
Use DatabaseName
--DB shrink
--获取database 空余空间, 决定是否作shrinkDB
exec [DBNAME].dbo.sp_spaceused
DBCC ShrinkDB(DBNAME)
--Log file shrink
Use DatabaseName
GO
Alter Database DatabaseName Set Recovery Simple
GO
Alter Database DatabaseName Set Recovery Full
GO
DBCC SHRINKFILE ('Log ......
用sql操作oracle的blob字段
1、查询
select utl_raw.cast_to_varchar2(dlob),id from system.t_htinfo
2、插入
insert into system.t_htinfo values ('3',utl_raw.cast_to_raw('你'));
3、更新
update system.t_htinfo set fld_value=utl_raw.cast_to_raw('1') where fh_nm=1820648 and form_index=52
......
----------------------------------------------------------------------
1、SQL数据库恢复模型
----------------------------------------------------------------------
1)完全恢复模型
-----------------
(1)备份时要备份数据库的数据文件和日志文件
(2)还原时使用数据库的备份的数据文件副本和全部日志信 ......