 |
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

May 11th, 2006, 08:24 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
problem with a stored proc trying to return blobs
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.
|

May 11th, 2006, 05:49 PM
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
|
|
First of all text, ntext and image can be parameters to a stored procedure, and can even be output parameters, so you could have a table where you use writetext and updatetext to build it up, then use readtext. Give that a try
David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
|

May 12th, 2006, 09:36 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok.. I'll give you the quick and skinny of everything that went on to correct this problem.
Basically, I didn't want to modify the ASP page. I wanted some way to have the SQL output what it needed to so that the ASP would get exactly what it expected, since its code was already correct.
Clearly, the problem lay in that the varchar variable type only allows up to 8k characters. The next step was to try blobs, which we found out that stored procs do not like. I started to go off the idea of temp tables, but I used the 'table' variable type instead, so that I wouldn't have to drop it after the stored proc finished executing. Then I set the columns in the table variable to text, and I tried to set the column equal to a select of what was already in the table + the new value. This did not work. I tried
a different method called updatetext which also didn't work. SQL was like "you're still trying to use a blob, and that's not happening." It simply would not let me subquery the table, concatenate on the next value, and submit it back to the table.
I then switched over to a temp table and tried a few options, but I still was not able to create a single, comma delimited string of values. I finally ended up populating columns in a temp table. Because I only needed the first two columns to carry the values, I let the last 2 columns fill with null through the whole table. The last record, I left the first two columns null, and populated the last 2 with their values, which were based on however many percentage values were populated in the first two columns. It looked like this:
22.22 | date | NULL | NULL
22.22 | date | NULL | NULL
22.22 | date | NULL | NULL
22.22 | date | NULL | NULL
NULL | NULL | valu | valu
I did have to change the ASP page, but it was only a minor one. I looped through my record set, and said that if the first column was null, look for the last two values, otherwise append strings with values from the first 2 columns. It was a 5 minute change to the ASP file.
|
|
 |