July 31, 2017 at 12:10 pm
Hi,
I'm trying to assign a concatenated string to a variable, in 2008 R2. I've tried both Concat() and the + operator, but receive syntax errors. E.g.,
DECLARE @s_FilePath nvarchar(255) = '' ;
@s_FilePath = 'what ' + 'the?' ;
returns an odbc error, I have no idea why:
Execute: ODBC Error (102): SQLExecDirectW Client: Server: Error line: 2 Error level: 15 Message State: 1 SQL State: 42000 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '@s_FilePath'.; DECLARE @s_FilePath nvarchar(255) ; @s_FilePath = N'First , ' + N'Second' ;
July 31, 2017 at 12:14 pm
SqlServerCampbell - Monday, July 31, 2017 12:10 PMHi,I'm trying to assign a concatenated string to a variable, in 2008 R2. I've tried both Concat() and the + operator, but receive syntax errors. E.g.,
DECLARE @s_FilePath nvarchar(255) = '' ;
@s_FilePath = 'what ' + 'the?' ;returns an odbc error, I have no idea why:
Execute: ODBC Error (102): SQLExecDirectW Client: Server: Error line: 2 Error level: 15 Message State: 1 SQL State: 42000 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '@s_FilePath'.; DECLARE @s_FilePath nvarchar(255) ; @s_FilePath = N'First , ' + N'Second' ;
On the second line, you need to use SET:
SET @s_FilePath = 'what ' + 'the?' ;
Sue
July 31, 2017 at 12:16 pm
you are missing the SET statement, it looks like to me.
Could you try this format instead?
DECLARE @s_FilePath nvarchar(255) = '' ;
SET @s_FilePath = 'what ' + 'the?' ;
Lowell
July 31, 2017 at 12:19 pm
Lowell - Monday, July 31, 2017 12:16 PMyou are missing the SET statement, it looks like to me.Could you try this format instead?
DECLARE @s_FilePath nvarchar(255) = '' ;
SET @s_FilePath = 'what ' + 'the?' ;
That's the ticket. Thanks Lowell and Sue.
July 31, 2017 at 1:13 pm
CONCAT errors in SQL Server 2008 because it wasn't added to TSQL until 2012:
https://docs.microsoft.com/en-us/sql/t-sql/functions/concat-transact-sql
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply