sql server - In SQL, exporting the table as text with formats and rules -


i novice in sql world; i've been searching site couple of hours , not find answer.

i'm using sql server management studio arrange table of customers columns:

name, address1, address2, address3, city, state, zipcode,  item_purchased, quantity_purchased, etc... 

however i've been trying format table texts in such way:

john smith
123 sql street
los angeles, ca 90001

item_purchased - quantity_purchased

would possible achieve in sql? if not, interested know way around in java or python input/output method.

brad,

try this:

select name + char(13) + case when ltrim(rtrim(isnull([address1],''))) <> '' ltrim(rtrim(isnull([address1],''))) + char(13) else '' end + case when ltrim(rtrim(isnull([address2],''))) <> '' ltrim(rtrim(isnull([address2],''))) + char(13) else '' end + case when ltrim(rtrim(isnull([address3],''))) <> '' ltrim(rtrim(isnull([address3],''))) + char(13) else '' end + case when ltrim(rtrim(isnull([city],''))) <> '' ltrim(rtrim(isnull([city],''))) + char(13) else '' end + case when ltrim(rtrim(isnull([state],''))) <> '' ltrim(rtrim(isnull([state],''))) + char(13) else '' end + case when ltrim(rtrim(isnull([zipcode],''))) <> '' ltrim(rtrim(isnull([zipcode],''))) + char(13) else '' end + case when ltrim(rtrim(isnull([item_purchased],''))) <> '' ltrim(rtrim(isnull([item_purchased],''))) else '' end + ' - ' + case when ltrim(rtrim(isnull([quantity_purchased],''))) <> '' ltrim(rtrim(isnull([quantity_purchased],''))) + char(13) else '' end customers 

you can either assign output variable single row or table printing.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -