Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to Concatenate 2 columns together with a / inbetween with no spaces.

This is the error message

Msg 102, Level 15, State 1, Line 11<br />
Incorrect syntax near '/'.


This is the code that I used

SQL
SELECT CONCAT(SLH_BOOK, '/' ,SLH_PAGE) BOOK_PG,


What I have tried:

This is what I have tried
SQL
SELECT CONCAT(SLH_BOOK, "/" ,SLH_PAGE) BOOK_PG,
Posted
Updated 7-Jan-21 20:04pm
v2

For SQL Server 2012 or later, your first code block should work, even if the columns are not already strings:
CONCAT (Transact-SQL) - SQL Server | Microsoft Docs[^]

The second code block would not work, since SQL Server doesn't use " for strings.

If you're using a different DBMS, you will need to tell us which one.
 
Share this answer
 
You need + between your and can do this much more easily as:

SELECT SLH_BOOK + '/'+ SLH_PAGE

But If you really want to make sure there is no space in between, you should do something like:

SELECT RTRIM(SLH_BOOK) + '/'+ LTRIM(SLH_PAGE)

ALSO, you may have to cast SLH_PAGE to a string if it's an INT
 
Share this answer
 

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