Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:56:28+00:00 2026-05-25T00:56:28+00:00

I have SQL query like SELECT *, dbo.func(@param1, a.point) as fValue FROM dbo.table AS

  • 0

I have SQL query like

SELECT *, dbo.func(@param1, a.point) as fValue 
FROM dbo.table AS a 
WHERE dbo.func(@param1, a.point) < @param2

When this query is executed only once, everything is fine, but when I have array of input @param1 values let’s say, over 100 values, executing and fetching results for every value take s a lot of time.

Is it possible to pass array of @param1 into the query somehow, and receive dataset for all the input values, instead of executing it for each value?

function func() doing some math on 2 values. @param1 and a.point are type of double. and, yeah, a.point – is not an ID, and it is not a unique value.

I know, it should be really easy, but it looks like I’m missing something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:56:29+00:00Added an answer on May 25, 2026 at 12:56 am

    What exactly does dbo.func() do? Is it possible that you could insert the 100 values into a table structure, and perform that operation on the set of 100 all at once, instead of 1×1 100 times?

    As an example, let’s say you have this function, which just turns a comma-separated list of float values into a single-column table:

    CREATE FUNCTION dbo.ListFloats
    (
        @List VARCHAR(MAX)
    )
    RETURNS TABLE
    RETURN
    (
        SELECT i = CONVERT(FLOAT, Item)
        FROM
        (
            SELECT Item = x.i.value('(./text())[1]', 'FLOAT')
            FROM
            (
                SELECT [XML] = CONVERT(XML, '<i>'
                    + REPLACE(@List, ',', '</i><i>')
                    + '</i>').query('.')
            ) AS a
            CROSS APPLY
            [XML].nodes('i') AS x(i)
        ) AS y
        WHERE Item IS NOT NULL
    );
    GO
    

    Now you should be able to get your floats in a set by simply saying:

    SELECT i FROM dbo.ListFloats('1.5, 3.0, 2.45, 1.9');
    

    Taking that a step further, let’s say dbo.func() takes these two inputs and says something like:

    RETURN (SELECT (@param1 + @param2 / @param2));
    

    Now, I know that you’ve always been told that modularization and encapsulation are good, but in the case of inline functions, I would suggest you avoid the function that gets this result (again you haven’t explained what dbo.func() does, so I’m just guessing this will be easy) and do it inline. So instead of calling dbo.func() – twice for each row, no less – you can just say:

    DECLARE 
        @Param1Array VARCHAR(MAX) = '1.5, 3.0, 2.45, 1.9',
        @Param2 FLOAT = 2.0;
    
    WITH x AS 
    (
        SELECT t.point, x.i, fValue = ((x.i + t.point)/t.point) 
        FROM dbo.[table] AS t
        CROSS JOIN dbo.ListFloats(@Param1Array) AS x
    )
    SELECT point, i, fValue FROM x
    --WHERE fValue < @Param2
    ;
    

    The keys are:

    1. Avoiding processing each parameter individually.

    2. Avoiding the individual calculations off in its own separate module.

    3. Performing calculations as few times as possible.

    If you can’t change the structure this much, then at the very least, avoid calculating the function twice by writing instead:

    ;WITH x AS 
    (
        SELECT *, dbo.func(@param1, a.point) as fValue 
        FROM dbo.table AS a 
    )
    SELECT * FROM x 
        WHERE fValue < @param2;
    

    If you provide details about the data types, what dbo.func() does, etc., people will be able to provide more tangible advice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I have a SQL Query like this one: SELECT X, Y FROM
I have the following SQL query - SELECT * FROM dbo.LocalContacts WHERE name LIKE
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a SQL SELECT query which has a LIKE clause containing an underscore,
I have a simple SQL 'Select' query, and I'd like to dump the results
I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
I have a result from an SQL query that I would like to sort
My query looks like: SELECT * FROM dbo.TestTable TT JOIN dbo.fnListParseAndSplit('test,tt,zz,er,ts',',') L ON TT.Name
I have a query that looks like the following: SELECT someString FROM ( SELECT
I have a sql server query question. I have a table like below. Giving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.