列在mssql中对齐文本数据 [英] Column Aligning Text Data in mssql

查看:132
本文介绍了列在mssql中对齐文本数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表中有Column - Product,Description_Sales,Description_Purchase。



我想通过左对齐为每个列数据编写用于选择数据的sql脚本。

下面我的脚本的结果显示为组合句子。

我要做的是第一列左对齐然后留下几个空格,之后发送列左对齐然后空格,

然后第三列左对齐。





  CREATE   procedure  SearchbyProductDescription 

@status nvarchar 255

< span class =code-keyword> as
选择 Product.Product_Code + Product.Description_Sales + Product.Description_Purchase 来自产品其中​​ Product.Description_Sales 喜欢 @ status + ' % '







谢谢,

ttds,



已添加代码块[/编辑]

解决方案

这是您要找的?< br $>


  SELECT   LEFT (CONCAT(Product.Product_Code,SPACE( 8 )), 8 ),
LEFT (CONCAT(Product.Description_Sales,SPACE( 12 )), 12 ),
LEFT (CONCAT(Product.Description_Purchase,SPACE( 30 )), 30
FROM 产品 where Product.Description_Sales LIKE CONCAT( @ status ' %'





这假设列长度应分别为8,12和30。您需要根据需要更改8,12,30这些数字。



替代方案:

  SELECT  CONCAT( LEFT (CONCAT(Product.Product_Code,SPACE( 8 )), 8 ),
LEFT (CONCAT(产品) .Description_Sales,SPACE( 12 )), 12 ),
LEFT (CONCAT(Product.Description_Purchase,SPACE( 30 )), 30 ))
FROM 产品其中 Product.Description_Sales LIKE CONCAT( @ status ' %'


There have there columns - Product, Description_Sales,Description_Purchase in table .

I would like to write sql script for selecting data by left aligning for each column data.
The result of my script below is showed as combine sentences.
what I want to do is first column with left align then left a few space, after that send column with left align then space ,
then third column with left align.


CREATE procedure SearchbyProductDescription
(
    @status nvarchar(255)
)
as
select  Product.Product_Code + Product.Description_Sales  + Product.Description_Purchase  from Product where Product.Description_Sales like @status + '%'




thanks,
ttds,

[Edit]Code block added[/Edit]

解决方案

Is this what you are looking for?

SELECT LEFT(CONCAT(Product.Product_Code,SPACE(8)),8),
       LEFT(CONCAT(Product.Description_Sales,SPACE(12)),12),
       LEFT(CONCAT(Product.Description_Purchase,SPACE(30)),30)
       FROM Product where Product.Description_Sales LIKE CONCAT(@status,'%')



This assumes that the column lengths should be 8, 12, and 30 respectively. You will need to alter the 8, 12, 30 numbers to your needs.

An Alternative:

SELECT CONCAT(LEFT(CONCAT(Product.Product_Code,SPACE(8)),8),
       LEFT(CONCAT(Product.Description_Sales,SPACE(12)),12),
       LEFT(CONCAT(Product.Description_Purchase,SPACE(30)),30))
       FROM Product where Product.Description_Sales LIKE CONCAT(@status,'%')


这篇关于列在mssql中对齐文本数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆