Home > Database > Mysql Tutorial > SQLServer中字符串左对齐或右对齐显示的sql语句

SQLServer中字符串左对齐或右对齐显示的sql语句

WBOY
Release: 2016-06-07 18:05:38
Original
3991 people have browsed it

在显示数据时需要对数据进行美观化显示。如左对齐,右对齐

知识点:
函数 replicate

以下代码是实现如下功能:
代码如下:
declare @sql varchar(200), --需填充的字符串
@char varchar(4), --填充使用的字符
@len int --填充后的长度
select @sql='abc'
select @char=' '
select @len=10
select (right(replicate(@char,@len)+@sql,@len)) 右对齐
,@sql+replicate(@char,@len-LEN(@sql)) 左对齐


作者: t134679
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template