UDF In SQL 2005 when invoked throws error msg 512: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

  • Hi,

    I have a UDF in SQL 2005 that throws the following error when invoked by a select query.

    msg 512: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

    I am passing parameters through a variable. However it runs fine when I pass the parameters by hard coding.

    1- IT RUNS FINE as I am hard coding the parameters

    select * from UDFxyz('08/01/2012','08/15/2012','ALL','New York,CANADA','ALL',Null,Null)

    2- THROWS ERROR when parameters are passed as variables

    Declare

    @Date1 datetime,

    @Date2 datetime,

    @CnCode varchar(8000),

    @Reg1 varchar(8000),

    @Cen varchar(3)

    Select

    @Date1 = '08/01/2012',

    @Date2 = '08/15/2012',

    @CnCode = 'ALL',

    @Reg1 ='New York,CANADA',

    @Cen ='ALL'

    select * from UDFxyz(@Date1,@Date2,@CnCode,@Reg1,@Cen,Null,Null)

    Please help!!

  • the error is occuring in the UDF itself, it looks like; can you post that? we can help you rewrite it to avoid that error.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for the help! any how, I could manage to resolve the issue. It was inside the UDF. I was supplying more than one value inside the udf using '='. I changed it to 'IN' and it worked.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply