Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with a stored proc trying to return blobs

Status
Not open for further replies.

phrozt

IS-IT--Management
Jul 8, 2004
78
US
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?
 
One varchar(somesizesmallerthan4kB) column, one-to-many table. If contents exceeds varchar size, append another row.

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
it has to be in one row....

i list why what you said won't work in my first post.

Here's an update of an idea of what I have so far:

declare @ptrCol1 binary(16)
declare @ptrCol2 binary(16)

CREATE TABLE #Inventory (
appendCol1 text NOT NULL ,
appendCol2 text NOT NULL,
static1 int NOT NULL,
static float NOT NULL
)

insert into #Inventory values('0','0',1,1)

[cursor logic]
Code:
if (len(@vchAppendCol1) + 5 > 8000) or (len(@vchAppendCol2) + 5 > 8000)
BEGIN


select @ptrCol1 = textptr(appendCol1), @ptrCol2 = textptr(appendCol2)
from #Inventory

updatetext #Inventory.appendCol1 @ptrCol1 null 0 @vchAppendCol1
updatetext #Inventory.appendCol2 @ptrCol2 null 0 @vchAppendCol2

select @vchAppendCol1 = ''
select @vchAppendCol2 = ''
END

[fetch cursor logic]

DROP TABLE #Inventory
 
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 your 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."

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top