用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
相关文档:
如下列出查询表达式,常用操作符,与SQL语句对应。
where 关键字的使用
public void MyWhere()
{
NorthwindDataContext dc = new NorthwindDataContext();
//查询产品名称以L开头的记录
var query = from p in dc.Products
where p.Prod ......
SQL操作全集
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREA ......
PL/SQL 不具备输入输出的能力
但是可以依靠环境来执行数值的输入输出给PL/SQL 块
SQLPLUS 环境用substitution variables 和 host(bind) variable 来传入数值给PL/SQL块
substitution variable: such as a preceding ampersand &a
host(bind) variable : such as a preceding colon :x
替 ......
有以下二张表:
政党表:政党ID,政党名称
议员表:议员ID,议员名称,政党ID
要求查询所有的政党信息,包含:政党名称,议员人数,并按议员人数的降序排列(不可以用子查询)。
正解:
SELECT a.name,
COUNT(b.id) AS counts
from zhen a
left join
yi b
on a.id=b.zhenid
GROUP ......
作者:不详 出处:网络转载 2009/11/18 10:35:22 阅读 109 次
技术水平总能在扯皮和吹毛求疵中得到提高。如果从来不“求疵”,可能就不会知道if(str != "")不如if(str != string.Empty)高效、批量插入和删除的sql语句是要那样写才执行最快、接口和抽象类的区别不仅是语言层面、 ......