Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select text fields in Stored Procedure

Author  Topic 

daniel.newman@bis-web.net
Yak Posting Veteran

71 Posts

Posted - 2001-05-22 : 07:39:17
Hello,

this is probably a really easy question, but I've got a stored procedure that is pulling data from dynamic tables (in that the table is a parameter of the SP).

For some tables I'm returning text fields, and for some I'm not. Within my ASP, I'm having trouble getting the data from these text fields, even though within Query Analyser, I can see the columns are being retrieved and have data within them.

My SP is:

CREATE PROCEDURE dbo.web_GetDisplayData
@table varchar(255),
@code varchar(10)
AS

DECLARE @SQL varchar(2000)

SELECT @SQL = 'SELECT Main.*, Summ.Summary, Doc.DisplayText, Powerpoint.FinancialResultCode FROM ' + @table + ' Main
INNER JOIN SummaryText Summ ON Summ.Code = Main.Code
LEFT OUTER JOIN DocumentText Doc ON Doc.Code = Main.Code
LEFT OUTER JOIN PowerpointPresentations AS Powerpoint ON Powerpoint.FinancialResultCode = Main.Code
WHERE Main.Code=''' + @code + ''''

EXEC(@SQL)

I remember reading something about blob fields where these had to be specified last in the SELECT statement. Is this the same for text fields? And if so, how would I specify them last when they're not being used at all times? Would I need a multiple if to determine what's needed, depending on the value of @table? There could be one field in Main that are text. Summary and DisplayText are also text fields.

Hope someone knows a nice simple way of fixing this problem, as it's driving me nuts!

Thanks in advance,
Daniel Newman.
   

- Advertisement -