Search code examples
sqlsql-serverfunctionselectsql-server-2000

SQL Select with a function


I have the following SQL Statement :

SELECT 
   RTRIM(LTRIM(REPLACE(LAGKART.VARENUMMER,CHAR(2),'')))                 AS ItemNo,
   RTRIM(LTRIM(REPLACE(LAGKART.SXSON,CHAR(2),'')))                          AS Season, 
   ISNULL(RTRIM(LTRIM(REPLACE(LAGKART.VARIANT1,CHAR(2),''))),'')            AS Variant1, 
   ISNULL(RTRIM(LTRIM(REPLACE(LAGKART.VARIANT2,CHAR(2),''))),'')            AS Variant2,
   (SELECT * 
    FROM [dbo].[B2BGetSpringFinal] ( LAGKART.VARENUMMER, 
                                    LAGKART.VARIANT1,
                                    LAGKART.VARIANT2
                                  )) AS SpringAvailable
FROM 
   LAGKART

But I get this error :

Msg 170, Level 15, State 1, Line 8
Incorrect syntax near '.'.

But if I call the function with fixed values :

SELECT 
   RTRIM(LTRIM(REPLACE(LAGKART.VARENUMMER,CHAR(2),'')))                 AS ItemNo,
   RTRIM(LTRIM(REPLACE(LAGKART.SXSON,CHAR(2),'')))                          AS Season, 
   ISNULL(RTRIM(LTRIM(REPLACE(LAGKART.VARIANT1,CHAR(2),''))),'')            AS Variant1, 
   ISNULL(RTRIM(LTRIM(REPLACE(LAGKART.VARIANT2,CHAR(2),''))),'')            AS Variant2,
   (SELECT * 
    FROM [dbo].[B2BGetSpringFinal] ( '6261', 
                                     'Black',
                                     'S'
                                   )) AS SpringAvailable
FROM 
   LAGKART   

I get the desired result.

Any ideas?

Br Mads


Solution

  • In SQL Server 2000, Only constants and @local_variables can be passed to table-valued functions. In SQL 2005 and greater this was fixed. You could try using a scalar function to get the SpringAvailable column value instead, or look at upgrading to a newer SQL Server version.