Skip to content
Advertisement

Stored procedure does not return value in column

I have this problem. I have this query in which I used to model a stored procedure and I want to get the value in the column clr_bal_amt. I want it to return as a string from the database column.

However it does not return it. The query executes, but it does not get the value in that column. The stored procedure looks like this

I need some form of clarification. Why did this not return that value in that clr_bal_amt column?

Edited

The SQL is looking like this now

Edits2

Is there something I am missing?

Advertisement

Answer

As I mentioned QUOTENAME accepts a sysname as a parameter (a synonym of nvarchar(128) NOT NULL), and your variable @query is defined as an nvarchar(MAX). As such if it’s 129 or more characters long it’ll be truncated; your value is clearly more than 128 characters.

Just use REPLACE:

As a bit of shameless self promotion, I explain this scenario more in-depth here.


To add emphasis on the OP’s attempt to implement this, your attempt is not the same:

Notice the lack of trailing and leading single quotes ('). The single quotes are needed. REPLACE replaces characters, it doesn’t delimit identify them like QUOTENAME does.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement