Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql server: concatinate column value without trailing or leading comma

DECLARE @x TABLE(Id INT, City VARCHAR(32), Province VARCHAR(32), Country VARCHAR(32));

INSERT @x(Id, City, Province, Country) VALUES
(1,'Vancouver','British Columbia','Canada'),
(2,'New York' , null             , null   ),
(3, null      ,'Adama'           , null   ),
(4, null      , null             ,'France'),
(5,'Winnepeg' ,'Manitoba'        , null   ),
(6, null      ,'Quebec'          ,'Canada'),
(7,'Seattle'  , null             ,'USA'   );

SELECT Id, Location = STUFF(
      COALESCE(', ' + RTRIM(City),     '') 
    + COALESCE(', ' + RTRIM(Province), '') 
    + COALESCE(', ' + RTRIM(Country),  '')
    , 1, 2, '')
  FROM @x;
Comment

PREVIOUS NEXT
Code Example
Sql :: SQL Primary Key single column 
Sql :: list enums sql 
Sql :: get the previous column of a table in mysql 
Sql :: sql run online 
Sql :: teller stamp , bmo , PDF 
Sql :: delete recurring email keep smallest id number 
Sql :: trigger value from maltiple table to single table mysql 
Sql :: how to innjert in other database 
Sql :: sql Contain declare sample 
Sql :: permisos en mysql 
Sql :: postgresql check if role exists 
Sql :: virtuoso sql query tutorial 
Sql :: ring PostgreSQL 
Sql :: mysql where in maintain order 
Sql :: xampp increame mysql speed 
Sql :: greater than and less than in mysql query 
Sql :: subconjuntos da linguagem SQL 
Sql :: SQL MAX() and MIN() in Nested SELECT 
Sql :: c# select mssql 
Sql :: kimball data warehouse sql calendar 
Sql :: how to insert a ROWGUIDCOL into a table 
Sql :: how to add session data into mysql database from button 
Sql :: MySQL Min And As 
Sql :: mysql convert charset 
Sql :: mysql c commands 
Sql :: how to add mysql to path on termin after installation 
Sql :: ring MySQL store binary data and special characters in the database after processing 
Sql :: mysql select max and corresponding row 
Sql :: Uninstall mysql community server in centos 7 
Sql :: write sql query to show the details start from digit 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =