Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    134

    Unanswered: Get Field Headings?

    I use the following to get the column names from a table but it is giving the error "Incorrect syntax near the keyword 'Where'"

    Here is the Stored Proc:
    Code:
    CREATE PROCEDURE usp_GetTemplatePrompts
    
    @cCode varchar(5)
    
    AS
    
    declare @cTableName varchar(100), @iError int, @cError varchar(255)
    
    SELECT @cTableName = s.TableName
    FROM tbShapes AS s INNER JOIN tbProductCodes AS pc
    ON s.Shape = pc.fkShape
    WHERE pc.Code = @cCode
    
    SELECT @iError = @@Error
    if(@iError = 0)
    	BEGIN
    	EXEC('SELECT *  FROM ' + @cTableName + ' WHERE Template = 0')
    	SELECT @iError = @@Error
    	END
    
    if(@iError <> 0)
    	BEGIN
    	set @cError = 'Error while attempting to get input fields for product ' + @cCode + '.'
    	RAISERROR(@cError, 16, 1)
    	END
    GO
    The table structure is as follows:

    Code:
    tbProductAccounts
    Account (PK) | Description 
    
    tbProductCodes
    Code (PK) | fkAccount | fkShape | Description
    
    tbShapes
    Shape (PK) | TableName | ShapeName
    
    tbDoubleT
    Template (PK) | fkCode | SectionName | Width | Height | Flange
    
    tbRectangular
    Template (PK) | fkCode | SectionName | Width | Height
    
    tbCircular
    Template (PK) | fkCode | SectionName | Radius
    
    tbTSection
    Template (PK) | fkCode | SectionName | X1 | Y1 | X2 | Y2
    Any ideas?

    Mike B
    Last edited by MikeB_2k4; 03-17-04 at 12:00.

  2. #2
    Join Date
    Dec 2003
    Posts
    7
    It looks like your first SELECT isn't coming back with a tablename.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •