实现SQL SERVER 下的PadLeft函数
例如 在做自动编号这样使用
int nextID=da.GetMaxNum()+1;
this.txtCode.Text = nextID.ToString().PadLeft(6, '0');
今天客户想要在用户表里加个工号字段,这个字段是自动生成的,这个很容易实现。但是用户表里已经有300多条记录,需要编号,手工录入
显然太麻烦,实施人员也会感觉枯燥乏味,我就想在数据库里有写段脚本自动编号,发现数据里没提供类似于右对齐的函数。
于是左查右看,就写了这么个自定义函数
--功能:右对齐的字符,在左边用指定的字符填充以达到指定的总长度。
--@num:原始字符@paddingChar:填充字符 @totalWidth:结果字符串中的字符数
--create by guoliang 2009/06/12
create function PadLeft(@num varchar(16),@paddingChar char(1),@totalWidth int)
returns varchar(16) as
begin
declare @curStr varchar(16)
select @curStr = isnull(replicate(@paddingChar,@totalWidth - len(isnull(@num ,0))), '') + @num
return @curStr
end
--测试函数:
SELECT dbo.PadLeft('8', '0', 6)
----------------
000008
(所影响的行数为 1 行)
然后用游标一行一行取出来,修改工号字段就ok了.
实现SQL SERVER 下的PadLeft函数相关推荐
- SQL Server中的STRING_SPLIT函数
This article will cover the STRING_SPLIT function in SQL Server including an overview and detailed u ...
- 学习SQL:SQL Server日期和时间函数
So far, we haven't talked about SQL Server date and time functions. Today we'll change that. We'll t ...
- 什么是SQL Server GETDATE()函数?
Hey, readers! In our previous article, we had understood the working of SQL Server DATEPART() functi ...
- coalesce函数_什么是SQL Server COALESCE()函数?
coalesce函数 Hey, folks! In this article, we will be focusing on SQL Server COALESCE() function. 嘿伙计! ...
- percent sql_使用SQL Server中的PERCENT_RANK函数计算SQL百分位数
percent sql This article explores the SQL Server PERCENT_RANK analytical function to calculate SQL P ...
- SQL Server多语句表值函数
In this article, we will learn multi-statement table-valued functions (MSTVFs) basics and then we wi ...
- C# 学习笔记(19)操作SQL Server下
C# 学习笔记(19)操作SQL Server下 ADO.net操作数据库 这应该是比较老的技术了,以后有空的话学学 Linq /// <summary> /// 数据库使用类 /// & ...
- 什么是SQL Server TRIM()函数?
Hello, readers. In today's article, we will be focusing on SQL Server TRIM() function in detail. 您好, ...
- sql dateadd函数_什么是SQL Server DATEADD()函数?
sql dateadd函数 Hey, folks! In this article, we will be focusing on SQL Server DATEADD() function in d ...
最新文章
- 一款嵌入式监听地图测试软件(开发)
- 深度学习总结:continuous actions和asyncronous advanteage actor-critic
- 大四中软实习笔记20130226
- SQL实战篇:SQL解决近X天的问题
- 【20171123】【GITC精华演讲】贝业新兄弟李济宏:如何做到企业信息化建设的加减乘除...
- asp.net 的page 基类页面 做一些判断 可以定义一个基类页面 继承Page类 然后重写OnPreLoad事件...
- flask中的session,render_template()第二和参数是字典
- leetcode513. 找树左下角的值(dfs)
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named XXX
- 【零基础学Java】—static关键字概述(十六)
- 成年人的世界,嘴上喊的都是主义,心里装的都是生意
- NodeJs之数据库异常处理
- mac推箱子c语言,c语言写的推箱子源码,非常适合新手学习
- 抖音便捷小空调特效 html+css+js
- Xcode8 及 iOS 10 的适配
- Linux修改配置文件(自动)
- ubuntu compiz 不能启动
- SPA项目开发之首页导航+左侧菜单
- 国腾GM7123C:功能RGB转VGA芯片方案简介
- minitab画出主效应图并画出等值线图
热门文章
- linux下collada-dom编译,COLLADA DOM Tutorial
- python中列表用某个数字出现的次数_Python实现统计给定列表中指定数字出现次数的方法...
- 计算机教学实验操作环境,一种基于虚拟机的个性化计算机实验教学环境.pdf
- html中可以添加几个类,从一个类中向一个HtmlHead对象添加多个元素
- 网站服务器被攻击的形式,服务器被攻击的不同表现类型以及应对策略
- php创蓝253四要素认证_PHP下基于创蓝253接口的短信发送
- 机器学习和图像资源整理
- 【杂谈】从学员到专栏作者、讲师,我在有三AI学习与名利双收的故事
- 全球及中国农业保险市场营销状况与运营价值分析报告2022版
- how to fix error 25007 : loadlibraryshim()