用SQL生成流水号
用SQL生成流水号
转:韦江涛 发表于2010年02月03日 09:38 阅读(4) 评论(0)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_FillNumberWithZero]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_FillNumberWithZero]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_FormatDate]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_FormatDate]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_GetNewFlowNumber]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_GetNewFlowNumber]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_GetNowDate]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_GetNowDate]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
/*
生成流水号后面几位数字字符的相关函数
不足位数在左边用0填充
*/
CREATE FUNCTION dbo.fn_FillNumberWithZero
(
--填充的数字
@num int,
--总位数
@len int
)
RETURNS varchar(50) AS
BEGIN
--如果传入的流水号大于总的长度,那么直接返回流水号字符串格式
if(len(Convert(varchar(50),@num))>@len)
return Convert(varchar(50),@num)
ELSE
BEGIN
--需要填充0的位数
declare @NeedFillLen int
set @NeedFillLen=@Len-len(Convert(varchar(50),@num))
--获取需要填充的0的字符串
declare @i int
set @i=0
declare @temp varchar(50)
set @temp=N''
while @i<@NeedFillLen
BEGIN
SET @temp=@temp+'0'
SET @i=@i+1
END
--返回组后的字符串
return @temp+Convert(varchar(50),@num)
END
return ''
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
相关文档:
1. 查看数据库的版本
select @@version
2. 查看数据库所在机器操作系统参数
exec master..xp_msver
3. 查看数据库启动的参数
sp_configure
4. 查看数据库启动时间
select convert(varchar(30),login_time,120) from master ......
SQL手工注入大全
2006年08月11日 星期五 21:00
比方说在查询id是50的数据时,如果用户传近来的参数是50 and 1=1,如果没有设置过滤的话,可以直接查出来,SQL 注入一般在ASP程序中遇到最多,
看看下面的
1.判断是否有注入
;and 1=1
;and 1=2
2.初步判断是否是mssql
;and user>0
3.判断数据库系统
;and ......
变量声明
Syntax:
identifier [CONSTANT] datatype [NOT NULL] [:= | DEFAULT expr];
SQL> declare
2 a date;
3 b number(20) not null :=100;
4 c varchar2(10);
5 d constant number(20) default 1000;
6 begin
7 null;
8 end;
9 /
PL/SQL procedure successful ......
SQL code动态sql语句基本语法
1 :普通SQL语句可以用Exec执行
eg: Select * from tableName
Exec('select * from tableName')
Exec sp_executesql N 'select * from tableName'
-- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
eg: declare @fname varchar(20)
......
作者:不详 出处:网络转载 2009/11/18 10:35:22 阅读 109 次
技术水平总能在扯皮和吹毛求疵中得到提高。如果从来不“求疵”,可能就不会知道if(str != "")不如if(str != string.Empty)高效、批量插入和删除的sql语句是要那样写才执行最快、接口和抽象类的区别不仅是语言层面、 ......