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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:20:02+00:00 2026-06-14T23:20:02+00:00

I have created the following function in my database Create FUNCTION [dbo].[CountUseer](@couponid INT) RETURNS

  • 0

I have created the following function in my database

Create FUNCTION [dbo].[CountUseer](@couponid INT)
RETURNS INT
AS
 BEGIN
 RETURN
(
  SELECT Count(cu.id) NofUses  --- this can only return one column
  FROM   Coupon as  c
  JOIN CouponUse as cu
    ON c.id = cu.couponid
  WHERE cu.couponid = @couponid
 )
 END 

Then I run this query

   ALTER TABLE dbo.Coupon
   ADD NofUses AS dbo.CountUseer(Id)

Now when I try to create an index on the column NofUses :

CREATE INDEX Noofusesindex ON Coupon (NofUses)  

I get this error:

Column ‘NofUses’ in table ‘Coupon’ cannot be used in an index or
statistics or as a partition key because it is non-deterministic.

  • 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-14T23:20:03+00:00Added an answer on June 14, 2026 at 11:20 pm

    Well, the error message really says it all: since this function is non-deterministic (e.g. when you call it with the same input parameters, there’s no guarantee you’ll get the same results every time), it cannot be indexed.

    The only way around this would be to make it a regular column (not based on a function), and just update the value stored in that column on a regular basis (by a SQL Agent job, for instance, or by a trigger on the CouponUse table, or some other mechanism)

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

Sidebar

Related Questions

I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
I have a strange one. Create a new form. Then add the following function
All, I have the following array and function, which will create a multidimensional array
I have the following function which creates a std::vector of iterators into another container:
I have the following function that takes a number like 5 and creates a
I have the following templated function... template< class T > T *create_object( lua_State *L
I have created following rule in the .htaccess file located at the root of
I have created following thing in android using android compatibility support package Basically i
I need to have the URL like photos/13/rate => I have created following routing

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.