So here's the setup. Basically, there's a chart that can display percentage levels based on the level of a product figured through an equation, over time. The time can be anywhere from the beginning of the day to the end of the day, to the begging of the time it started taking iventory to the current day. The app that creates the chart is expecting a set of values that are formatted to look like this: "value,value,value,value." Because it is percentages, that's 6 chars per value: "xx.xx,xx.xx,xx.xx,"
The problem comes when I'm trying to return a record of this data, because a varChar type variable is currently used as the variable type that holds the appended string. As you know, varchars max out at 8000 characters. At 6 chars a piece, you can hit 8000 characters VERY quickly. The other problem is, this stored proc doesn't just need to return one appended string (otherwise I'd just return all values and make the string in my ASP page). It returns TWO appended strings, 1 count row of one of the string columns (which is needed because there are not a number of columns, but rather all values concatenated in one string), and a value that is determined based off a block of logic run that is based off of the values selected which give the percentage equations.
Now... my proposed solution was to use text as a variable type. However, stored procs don't allow local variables to be set to text. My other idea was to make a variable of type table, and keep on selecting from that @tblVariable and updating the column, then returning all the needed columns from the table. However, SQL seems to have the same problem with that logic as well. Here's the current way I have things set up:
************************************************************
Declare @tblVar table (
appendCol1 text not null,
appendCol2 text not null,
single1 int not null,
single2 float not null,
)
insert into @tblVar values('0','0',1,1)
But then I'm hitting the same problem when I try to append the first column. I set it up like:
Update @tblVar set appendCol1 = (select appendCol1 from @tblVar) + ','
...
************************************************************
My errors are:
The text, ntext, and image data types are invalid in this subquery or aggregate expression.
Invalid operator for data type. Operator equals add, type equals text.
I'm sure the second one is because of the first error erroring out, but the first one is almost exactly what I saw when I set it up as a stored proc trying to set a @variable to type text.
The reason I have to do it like this, and can't just keep tossing in values, is because I have to have 2 columns that have to return variable amounts of data, and then I have 2 columns that return only one value from the entire stored proc. One is a count of one of the variable columns, the other is a value that is returned based on a block of logic that runs in the stored proc.
Can anyone lend a better solution?
The problem comes when I'm trying to return a record of this data, because a varChar type variable is currently used as the variable type that holds the appended string. As you know, varchars max out at 8000 characters. At 6 chars a piece, you can hit 8000 characters VERY quickly. The other problem is, this stored proc doesn't just need to return one appended string (otherwise I'd just return all values and make the string in my ASP page). It returns TWO appended strings, 1 count row of one of the string columns (which is needed because there are not a number of columns, but rather all values concatenated in one string), and a value that is determined based off a block of logic run that is based off of the values selected which give the percentage equations.
Now... my proposed solution was to use text as a variable type. However, stored procs don't allow local variables to be set to text. My other idea was to make a variable of type table, and keep on selecting from that @tblVariable and updating the column, then returning all the needed columns from the table. However, SQL seems to have the same problem with that logic as well. Here's the current way I have things set up:
************************************************************
Declare @tblVar table (
appendCol1 text not null,
appendCol2 text not null,
single1 int not null,
single2 float not null,
)
insert into @tblVar values('0','0',1,1)
But then I'm hitting the same problem when I try to append the first column. I set it up like:
Update @tblVar set appendCol1 = (select appendCol1 from @tblVar) + ','
...
************************************************************
My errors are:
The text, ntext, and image data types are invalid in this subquery or aggregate expression.
Invalid operator for data type. Operator equals add, type equals text.
I'm sure the second one is because of the first error erroring out, but the first one is almost exactly what I saw when I set it up as a stored proc trying to set a @variable to type text.
The reason I have to do it like this, and can't just keep tossing in values, is because I have to have 2 columns that have to return variable amounts of data, and then I have 2 columns that return only one value from the entire stored proc. One is a count of one of the variable columns, the other is a value that is returned based on a block of logic that runs in the stored proc.
Can anyone lend a better solution?