MSSQL 2005 - Concatenate strings

Hi,

How come this works:

select 'here comes' + ' joe'

But this gives me an error:

declare @boolValue bit
set @boolValue = 1

IF(@boolValue = 1)
BEGIN
                  RAISERROR( ('Nooooooo' + ' aaaaaaaaa') ,11, 1)
END



"Msg 102, Level 15, State 1, Line 6
Incorrect syntax near '('."


Thank you!! :)
EndelmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jinesh KamdarCommented:
Try these :

a) RAISERROR('Nooooooo' + ' aaaaaaaaa', 11, 1)
b) RAISERROR('Nooooooo' & ' aaaaaaaaa', 11, 1)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EndelmAuthor Commented:
No, it didn't work.

I could of course do this:


declare @boolValue bit
set @boolValue = 1

IF(@boolValue = 1)
BEGIN
                  declare @tmp varchar(50)
                  set @tmp = 'Nooooooo' + ' aaaaaaaaa'
                  RAISERROR( @tmp ,11, 1)
END

...but how long can the RAISERROR string be? Anyone?
0
Jinesh KamdarCommented:
Strange! Does this work - RAISERROR ('Nooooooo aaaaaaaaa', 11, 1)
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

EndelmAuthor Commented:
"The error message can have a maximum of 2,047 characters. "


http://msdn2.microsoft.com/en-us/library/ms178592.aspx
0
EndelmAuthor Commented:
yes, it does.
0
pbellovoxCommented:
Yes. Raiseerror is peculiar like this. I cant find any doc that explains why. You have 2 options to build a dynamic raiseerror message :
1. build string
declare @myMsg as varchar(500)
set @myMsg = 'fdsjfkds;fjdsf'
RAISERROR (@s, 16, 1)

2.use string substution (BOL extract)
DECLARE @DBID INT
SET @DBID = DB_ID()

DECLARE @DBNAME NVARCHAR(128)
SET @DBNAME = DB_NAME()

RAISERROR ('The current database ID is:%d, the database name is: %s.', 16, 1, @DBID, @DBNAME)

--where %d means int and %s means string

0
Jinesh KamdarCommented:
pbellovox is right. There's no documentation for that strange behavior. Check if this helps :
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_10231509.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.