Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Concatation without spaces

Author  Topic 

Analyzer
Posting Yak Master

115 Posts

Posted - 2015-04-09 : 11:51:13
Hi,

Trying to concatenate 2 variables without a space. Tried ++, coallese, RTRIM, LTRIM and all fail.

Delare @schema char(4), @tbl vchar(10)
Set @schema = 'test.', @tbl = 'results'

Select @schema ++ @tbl

Result I get is test. Results

Trying to build a string to import data so cannot have that space. Any ideas?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-04-09 : 12:10:02
SELECT @schema + @tbl

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-04-09 : 13:03:18
[code]
Select RTrim(@schema) + @tbl
[/code]
??

Your issue is probably that @schema is decalred as CHAR (which is fixed length, and thus will be space padded)

... notwithstanding that your example declared it as CHAR(4) which is shorter than the sample data 'test.' ... plus a few other typos.

Here's my test code
[code]

Declare @schema char(10), @tbl varchar(10)
SELECT @schema = 'test.', @tbl = 'results'

Select RTrim(@schema) + @tbl
[/code]
Go to Top of Page
   

- Advertisement -