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 8342979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:55:27+00:00 2026-06-09T05:55:27+00:00

In my past experience, I’ve always used functions in simple cases where I need

  • 0

In my past experience, I’ve always used functions in simple cases where I need to select a dataset, without a lot of complex logic, and I need to also pass a parameter.

I’ve recently been informed that I should avoid using functions in MSSQL at all costs, because they often cause performance issues, and sometimes their use causes indexing to not me used properly. Can anyone speak to this point, and explain in further detail if this is true, and some reasoning behind it?

  • 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-06-09T05:55:28+00:00Added an answer on June 9, 2026 at 5:55 am

    You have been advised naively.

    Scalar Functions

    WHERE dbo.fn_get_year(tbl.field) = 2012 will obfuscate tbl.field and make any index on it unusable.

    You will find much better performance with, for example, WHERE tbl.field >= '20120101' AND tbl.field < '20130101'.

    In the first example, every record has to be processed, because the optimiser can’t see through the function and infer which range of records will fit the criteria.

    In the second example, you make it very clear you want a continuous block of records from point a to point b. This enables the optimiser to use the index for a range seek.

    Table Valued Functions

    All of that is very different from SELECT * FROM dbo.my_function(@parameter) AS data. There is nothing wrong with table valued functions being used in that way.

    A complexity comes when joining the results of the function to another table or function.

    If the function is multi-statement (with IF blocks, etc, etc) then the whole result set of the function is returned before the join is processed.

    If the function is an inline-function (with just a RETURNS TABLE AS SELECT blah FROM blah) then SQL Server treats it as a macro (unless you tell it not to). This means that your function code is substituted into your query, and a brand new execution plan is built for your query. That may mean that only the relevant records from your function are ever processed due to index optimisation, etc.

    In short, ask the person who advised you to be exceptionally specific about their advice. If it remains never use functions just ignore them.

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

Sidebar

Related Questions

I need to select past 30 days data and find the no: rows....i am
I'm a Linux Python programmer with a (long) past Java experience I need a
I have used Jetty in the past but I have little experience with jWebSocket.
Warning: I have very little JavsScript experience. In my past programming experience, I usually
In the past I've had some experience of Qt in C++. I've now started
All my past programming experience has been in C++ on VS2003/8, Mostly service based
I need to know which are the APIs/library used for multithreading by MSVC .
My past CI experience is tightly coupled with CC.Net, but for sake of innovations
Just started to play around with node.js, have some past experience with JavaScript but
I have come accross vi-style keybindings for Emacs, but my past experience in mixing

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.