Discussion:
Error with no reference
(too old to reply)
thejamie
2009-06-24 16:30:01 UTC
Permalink
"Incorrect syntax near '' Expecting ID, QUOTED_ID, '.', or PSEUDOCOL"

Platform SQL 2008

I could find no error reference. There is also nothing regarding a
'PSEUDOCOL' type.

To reproduce:

CREATE FUNCTION [dbo].[fnCSVToTable] ( @StringInput VARCHAR(8000) )
RETURNS @OutputTable TABLE ( [String] VARCHAR(10) )
AS
BEGIN

DECLARE @String VARCHAR(10)
Declare @fldname varchar(10)
Declare @cnt tinyint
Set @cnt=1
WHILE LEN(@StringInput) > 0
BEGIN
SET @String = LEFT(@StringInput,
ISNULL(NULLIF(CHARINDEX(',', @StringInput) -
1, -1),
LEN(@StringInput)))
SET @StringInput = SUBSTRING(@StringInput,
ISNULL(NULLIF(CHARINDEX(',',
@StringInput), 0),
LEN(@StringInput)) + 1,
LEN(@StringInput))

Set @fldname='F'+convert(varchar(3),@cnt)--quotename(@fldname,'''')
INSERT INTO @OutputTable ( @fldname )
VALUES ( @String )

set @cnt=@cnt+1
END

RETURN
END


Still receive an error if the @fldname is replaced by
quotename(@fldname,'''') however, the error makes sense in the latter case.
--
Regards,
Jamie
Erland Sommarskog
2009-06-24 22:41:32 UTC
Permalink
Post by thejamie
"Incorrect syntax near '' Expecting ID, QUOTED_ID, '.', or PSEUDOCOL"
Looks like an error from some piece of incorrectly formed dynamic SQL.
How reproduce? Your function gave me the error:

Msg 102, Level 15, State 1, Procedure fnCSVToTable, Line 24
Which is obvious. You cannot have a variable in a column list.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Erland Sommarskog
2009-06-25 22:14:01 UTC
Permalink
Post by thejamie
"Incorrect syntax near '' Expecting ID, QUOTED_ID, '.', or PSEUDOCOL"
Platform SQL 2008
I could find no error reference. There is also nothing regarding a
'PSEUDOCOL' type.
This appears to be the result of some malformed dynamic SQL.
Not really sure what the function is supposed to reproduce, but when
I tried to create it, I got an error about incorrect syntax on this
Which is no surprise. You cannot have a variable in a column list. You
probably meant:

INSERT INTO @OutputTable (String) VALUES ( @fldname )
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Loading...