I faced to a huge problem when i coding some stored procedure. How to combine some string to sql string in stored procedure???

This is what i did upto now.

@WhereCondition = ' WHERE id = 102 '
DECLARE recoredSet CURSOR FOR
        SELECT SUM(Amount) as AmountSum FROM sale + @WhereCondition
OPEN recoredSet

--After above code I wrote fetch commands and it has no any problem.

In above code, @WhereCondition is assinged some value.
Eg: @WhereCondition = ' WHERE id = 5 '

But the problem is plus mark (+) is not supported. If Plus mark is not there, the code is working well.
My Problem is how to combined some string to a sql string like above code. I put and sign (&) instead of plus mark. But it doesnt work.

Recommended Answers

All 5 Replies

You can only do this when you concat strings to build the query, and then execute it with sp_executesql

It depends on database you are using. When you use an Oracle database you should use || (double pipe) to concat, + can be used with SQL Server and for MySQL you should use Concat('A', 'B')....

Those options work for concatenating column values, not for building a query.

im using sql server 2005. It is not supported CONCAT command....

@Pritaes: You've got a point and is more described in: Click Here, especially Click Here
Thank you for this opportunity to learn....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.