Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


SQL
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]
Posted
Updated 17-Mar-13 5:45am
v2

1 solution

Is this what you are looking for?

SQL
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:
SQL
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,'%')
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900