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.
Author |
Topic |
MikeB
Constraint Violating Yak Guru
387 Posts |
Posted - 2004-04-08 : 09:53:57
|
Using the following DDL and DML, a cross sectional area shoule be returned for a shape. The result I am getting is NULL.Any help?The DDL and DML will create 3 tables, 2 stored procs and 1 UDF. USE NORTHWIND GOCREATE TABLE [dbo].[tbProductTemplates] ( [TemplateID] [int] IDENTITY (1, 1) NOT NULL , [fkProductCode] [int] NOT NULL , [Template] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [fkMixID] [int] NULL ) ON [PRIMARY]GOINSERT INTO tbProductTemplates (fkProductCode, Template, fkMixID)SELECT 2001, 1, 1GOCREATE TABLE [dbo].[tbProductTemplateAttributeValues] ( [fkTemplateID] [int] NOT NULL , [fkAttributeID] [int] NOT NULL , [AttributeValue] [float] NOT NULL ) ON [PRIMARY]GOINSERT INTO tbProductTemplateAttributeValues (fkTemplateID, fkAttributeID, AttributeValue)SELECT 1, 1, 108 UNION ALLSELECT 1, 2, 10GOCREATE TABLE [dbo].[tbShapeAttributes] ( [AttributeID] [int] NOT NULL , [fkShapeID] [int] NOT NULL , [Attribute] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ) ON [PRIMARY]GOINSERT INTO tbShapeAttributes (AttributeID, fkShapeID, Attribute)SELECT 1, 1, 'Width' UNION ALLSELECT 1, 2, 'Height' GOCREATE FUNCTION RECTANGULAR_XSECTION(@fWidth float, @fHeight float)RETURNS floatASBEGINRETURN (@fWidth * @fHeight)ENDGOCREATE PROCEDURE usp_shapes_GetRectangularXSection@iTemplate int,@fResult float OUTPUTAS declare @fWidth float, @fHeight floatSELECT @fWidth = SUM(CASE sa.Attribute WHEN 'Width' THEN av.AttributeValue ElSE 0 END), @fHeight = SUM(CASE sa.Attribute WHEN 'Height' THEN av.AttributeValue ElSE 0 END)FROM tbProductTemplateAttributeValues AS av INNER JOIN tbShapeAttributes AS saON av.fkAttributeID = sa.AttributeIDWHERE av.fkTemplateID = @iTemplateSELECT @fResult = [dbo].[RECTANGULAR_XSECTION](@fWidth, @fHeight)GOCREATE PROCEDURE usp_shapes_GetXSection@iProductCode int,@iTemplateID int,@fResult float OUTPUTASif(@iProductCode = 2001) EXECUTE usp_shapes_GetRectangularXSection @iTemplateID, @fResultGOdeclare @fResult floatEXECUTE usp_shapes_GetXSection 2001, 1, @fResultSELECT @fResultGODROP TABLE tbProductTemplatesGODROP TABLE tbProductTemplateAttributeValuesGODROP TABLE tbShapeAttributesGODROP PROCEDURE usp_shapes_GetRectangularXSectionGODROP PROCEDURE usp_shapes_GetXSectionGODROP FUNCTION RECTANGULAR_XSECTIONGO I am getting a NULL result. Any ides?Mike B |
|
MikeB
Constraint Violating Yak Guru
387 Posts |
Posted - 2004-04-08 : 10:07:08
|
Correction to previous post:INSERT INTO tbProductTemplateAttributeValues (fkTemplateID, fkAttributeID, AttributeValue)SELECT 1, 1, 108 UNION ALLSELECT 1, 2, 10Should be INSERT INTO tbProductTemplateAttributeValues (fkTemplateID, fkAttributeID, AttributeValue)SELECT 1, 1, 108 UNION ALLSELECT 2, 1, 10*********************************************************************** New infomationCREATE PROCEDURE usp_shapes_GetRectangularXSection@iTemplate int,@fResult float OUTPUTAS declare @fWidth float, @fHeight floatSELECT @fWidth = SUM(CASE sa.Attribute WHEN 'Width' THEN av.AttributeValue ElSE 0 END), @fHeight = SUM(CASE sa.Attribute WHEN 'Height' THEN av.AttributeValue ElSE 0 END)FROM tbProductTemplateAttributeValues AS av INNER JOIN tbShapeAttributes AS saON av.fkAttributeID = sa.AttributeIDWHERE av.fkTemplateID = @iTemplateSELECT @fResult = [dbo].[RECTANGULAR_XSECTION](@fWidth, @fHeight)SELECT @fResult AS OkHereGOCREATE PROCEDURE usp_shapes_GetXSection@iProductCode int,@iTemplateID int,@fResult float OUTPUTASif(@iProductCode = 2001) BEGIN EXECUTE usp_shapes_GetRectangularXSection @iTemplateID, @fResult SELECT @fResult AS XSection ENDGOdeclare @fResult floatEXECUTE usp_shapes_GetXSection 2001, 1, @fResultSELECT @fResult AS Result[/code]In the above, the green is the correct answer, the read and blue are NULL. So the value isn't begin passed through the output parameters correctly?What am I doing wrong?Mike B |
|
|
MikeB
Constraint Violating Yak Guru
387 Posts |
Posted - 2004-04-08 : 11:15:08
|
Easier code to use and read. Minus the tables!USE NORTHWIND GOCREATE FUNCTION RECTANGULAR_XSECTION(@fWidth float, @fHeight float)RETURNS floatASBEGINRETURN (@fWidth * @fHeight)ENDGOCREATE PROCEDURE usp_shapes_GetRectangularXSection@fResult float OUTPUTASdeclare @fWidth float, @fHeight floatSELECT @fWidth = 108, @fHeight = 10SELECT @fResult = [dbo].[RECTANGULAR_XSECTION](@fWidth, @fHeight)GOCREATE PROCEDURE usp_shapes_GetXSection@fResult float OUTPUTASEXECUTE usp_shapes_GetRectangularXSection @fResultGOdeclare @fResult floatEXECUTE usp_shapes_GetXSection @fResultSELECT @fResult as ResultGODROP FUNCTION RECTANGULAR_XSECTIONGODROP PROCEDURE usp_shapes_GetRectangularXSectionGODROP PROCEDURE usp_shapes_GetXSectionGO Any ideas. This should not be returning NULL as the Result.Mike B |
|
|
MikeB
Constraint Violating Yak Guru
387 Posts |
Posted - 2004-04-08 : 11:44:46
|
I found it, I forgot "OUTPUT" on the call to the stored procedure!!Damn, simple, simple, simple!!!!Mike B |
|
|
|
|
|
|
|