Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 11th, 2006, 08:24 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.



Reply With Quote
  #2 (permalink)  
Old May 11th, 2006, 05:49 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , AZ, .
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #3 (permalink)  
Old May 12th, 2006, 09:36 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing return value of a Stored Proc in a Session mahajanvit ASP.NET 2.0 Basics 0 November 2nd, 2006 09:16 AM
Return 2 Recordsets from 1 Stored Proc Gordie Classic ASP Databases 0 July 3rd, 2006 05:34 PM
Return output variable to VB from SQL stored proc busterbunny BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 27th, 2006 09:24 PM
Need script Blobs stored File System xologist SQL Server 2000 2 May 1st, 2005 09:33 PM
Stored Proc. problem - newbie joeb SQL Server 2000 5 November 22nd, 2004 05:18 AM



All times are GMT -4. The time now is 02:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.