Results 1 to 5 of 5

Thread: function in where clause

  1. #1
    Join Date
    Sep 2009
    Posts
    3

    function in where clause

    Hi All

    I am writing a stored procedure which return rows

    here's stored procedure

    CREATE PROCEDURE [DBO].[SP_XYZ]
    AS
    SELECT * FROM TABLENAME WHERE FIELDNAME IN ([DBO].[FN_ABC])

    FUNCTION [DBO].[FN_ABC] return something like that

    'xx', 'AB','BC'

    Now

    I can't able to get query right stored procedure doesn't like function in where clause but i write some thing similar with out having function in where clause
    SELECT * FROM TABLENAME WHERE FIELDNAME IN ('xx', 'AB','BC') it works fine.

    let me explain what function is doing function get field in table which has value like xx;ab;bc;
    function replaces ";" and rearrage value like 'xx','ab','bc'

    Any advice or suggestion

    Thanks

    Ayaz

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    What type of function is fn_abc? Does it return string or table?

  3. #3
    Join Date
    Sep 2009
    Posts
    3
    it return string

  4. #4
    Join Date
    Sep 2009
    Posts
    3
    I did somthing like this and it work
    SET @STRING = [DBO].[FUNCTIONAME](P1,P2)
    EXEC ('SELECT * FROM TABLENAME WHERE (' + @STRING +')')

  5. #5
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    That should work or you can return table from function and use IN select functionname.

Posting Permissions

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