Click here to Skip to main content
15,893,161 members
Home / Discussions / Database
   

Database

 
GeneralRe: Oracle Dbase By c# Pin
unitecsoft28-Apr-04 8:08
unitecsoft28-Apr-04 8:08 
GeneralRe: Oracle Dbase By c# Pin
Chris Meech28-Apr-04 8:27
Chris Meech28-Apr-04 8:27 
Generaldbgdel.cpp _BLOCK_TYPE_IS_VALID Pin
dotbomb21-Apr-04 11:23
dotbomb21-Apr-04 11:23 
QuestionCREATE FUNCTION in SQL Server Version 7? Pin
-Dr_X-21-Apr-04 7:26
-Dr_X-21-Apr-04 7:26 
AnswerRe: CREATE FUNCTION in SQL Server Version 7? Pin
Jeff Varszegi21-Apr-04 7:33
professionalJeff Varszegi21-Apr-04 7:33 
GeneralRe: CREATE FUNCTION in SQL Server Version 7? Pin
-Dr_X-21-Apr-04 7:51
-Dr_X-21-Apr-04 7:51 
GeneralRe: CREATE FUNCTION in SQL Server Version 7? Pin
Jeff Varszegi21-Apr-04 7:57
professionalJeff Varszegi21-Apr-04 7:57 
GeneralRe: CREATE FUNCTION in SQL Server Version 7? Pin
-Dr_X-21-Apr-04 18:40
-Dr_X-21-Apr-04 18:40 
Thanks again. I won't be back to the client's site until Monday but it was kind of frustrating today...grrr... Nonetheless, I haven't had a chance to look into the view scenario. But, since I am restricting the user search results to a max of 100 records, I think that the view scenario may be the best solution as this point. Most of the time the output parameter from a query will suffice. The database in the app will be coasting along since everything is cached. That is why I didn't want to do the string concantenation in the app. Here was the function I was using in 2K toc oncantenate the Terminal Port Well Locations (Oil Industry). It obviously failed in SQL 7.0.
CREATE FUNCTION fn_SamplesTerminalPortWellLocationText
(
	@SampleID int
)
RETURNS varchar(1000)
AS
/*
	DROP FUNCTION fn_SamplesTerminalPortWellLocationText
	GRANT EXEC ON fn_SamplesTerminalPortWellLocationText TO xxxx

	select dbo.fn_SamplesTerminalPortWellLocationText(1) as test

	--GO
	DECLARE @SampleID int
	SELECT  @SampleID = 1
	Select  SampleID, sp_SamplesTerminalPortWellLocationText(SampleID)
	FROM	tblSamplesSample WHERE SampleID = @SampleID
*/
BEGIN

	DECLARE @RowCount int,
		@Debug bit,
		@Results varchar(1000)
	SELECT  @Debug = 0,
		@Results = ''

	-- Loop thru all of the terminal port and concantenate them together
	DECLARE @TerminalPortWellLocation varchar(75)

	DECLARE TPWL CURSOR FAST_FORWARD FOR
		SELECT	tp.TerminalPortWellLocation
		FROM 	tblSamplesSampleTerminalPortWellLocation stp,
			tblSamplesTerminalPortWellLocation tp
		WHERE	stp.TerminalPortWellLocationID = tp.TerminalPortWellLocationID
		AND	stp.SampleID = @SampleID
		AND	(stp.Deleted Is Null Or stp.Deleted = 0)
		ORDER BY TerminalPortWellLocation
	
	OPEN TPWL
	FETCH FROM TPWL 
	  INTO @TerminalPortWellLocation

	While @@Fetch_Status = 0
	BEGIN
		
		SELECT @Results = @Results + @TerminalPortWellLocation + ', '
	
		FETCH FROM TPWL 
	  	  INTO @TerminalPortWellLocation
	END
	-- Close & Deallocate Cursor
	Close TPWL
	Deallocate TPWL

	-- Trim the last comma
	-- Return the results
	IF (DataLength(@Results) > 2)
		SELECT @Results = SubString(@Results, 1, DataLength(@Results) - 2) 

	RETURN(@Results)

END

I have been using SQL for a while now as well, but hopefully you can help me in this area: Is there an easy way to execute a pivot table in SQL Server. I have completed the task but it is one UGLY procedure. It ended up being a cursor creating columns in a variable to be used in an exec(@variable) statement. Is there an easier way? I can send you the procedure but it is a couple hundred lines of code. Here is the begining of the main ugly query that is executing a string variable.
SELECT   tp.OrderBy, tp.PropertyTestID, Replace(tp.PropertyTestName, ',', '') AS PropertyTestName,
  SUM(CASE WHEN S.SampleID = 109 THEN ResultDecimal ELSE NULL END) AS [N/A109 03/31/2004],  
  SUM(CASE WHEN S.SampleID = 108 THEN ResultDecimal ELSE NULL END) AS [N/A108 03/30/2004],  
  SUM(CASE WHEN S.SampleID = 107 THEN ResultDecimal ELSE NULL END) AS [N/A107 03/17/2004],  
  SUM(CASE WHEN S.SampleID = 106 THEN ResultDecimal ELSE NULL END) AS [N/A106 03/01/2004],  
  SUM(CASE WHEN S.SampleID = 105 THEN ResultDecimal ELSE NULL END) AS [N/A105 01/05/2004],  
  SUM(CASE WHEN S.SampleID = 104 THEN ResultDecimal ELSE NULL END) AS [N/A104 11/17/2003]
FROM     tblSamplesPropertyTest tp, 
         ........[the rest of the query blah, blah blah...]

Obviously all subsequent queries from this main query are executed from a string variables as well. Functions are out of the question at this point as well. Is there a better way? Tell me there is...Point me in the right direction.
If you would like the entire procedure, I can email it to you.

Thanks again,
Michael

I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious.
Vince Lombardi (1913-1970)
GeneralRe: CREATE FUNCTION in SQL Server Version 7? Pin
Jeff Varszegi22-Apr-04 10:51
professionalJeff Varszegi22-Apr-04 10:51 
GeneralRe: CREATE FUNCTION in SQL Server Version 7? Pin
Sylvain-Marc Girard27-Apr-04 7:51
sussSylvain-Marc Girard27-Apr-04 7:51 
General1002 (AFX_SQL_ERROR_RECORDSET_FORWARD_ONLY)) Error When opening Recordset Pin
petecg21-Apr-04 6:01
petecg21-Apr-04 6:01 
GeneralSql server CE newbie Pin
Lvca21-Apr-04 2:37
Lvca21-Apr-04 2:37 
Generalproblem use ado with stored procedure Pin
Satervalley20-Apr-04 23:10
Satervalley20-Apr-04 23:10 
GeneralGet value of newid() function of SQLsrv2k from ASP Pin
_skidrow_vn_20-Apr-04 22:16
_skidrow_vn_20-Apr-04 22:16 
GeneralRe: Get value of newid() function of SQLsrv2k from ASP Pin
-Dr_X-21-Apr-04 19:53
-Dr_X-21-Apr-04 19:53 
GeneralJoin Pin
Robert197420-Apr-04 8:10
Robert197420-Apr-04 8:10 
GeneralRe: Join Pin
-Dr_X-20-Apr-04 9:47
-Dr_X-20-Apr-04 9:47 
GeneralRe: Join Pin
Robert197420-Apr-04 10:19
Robert197420-Apr-04 10:19 
GeneralCorrection Pin
Jeff Varszegi21-Apr-04 7:38
professionalJeff Varszegi21-Apr-04 7:38 
GeneralSQL statement execution plan (SQL Server 2000) Pin
Xiangyang Liu 刘向阳20-Apr-04 4:35
Xiangyang Liu 刘向阳20-Apr-04 4:35 
GeneralRe: SQL statement execution plan (SQL Server 2000) Pin
Mike Dimmick20-Apr-04 6:11
Mike Dimmick20-Apr-04 6:11 
GeneralRe: SQL statement execution plan (SQL Server 2000) Pin
XiangYangLiu20-Apr-04 22:16
sussXiangYangLiu20-Apr-04 22:16 
GeneralRunning Oracle SQL DDL from the IDE Pin
Ranjan Banerji20-Apr-04 4:13
Ranjan Banerji20-Apr-04 4:13 
GeneralRe: Running Oracle SQL DDL from the IDE Pin
RichardGrimmer21-Apr-04 2:27
RichardGrimmer21-Apr-04 2:27 
GeneralRe: Running Oracle SQL DDL from the IDE Pin
Ranjan Banerji27-Apr-04 4:10
Ranjan Banerji27-Apr-04 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.