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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:05:50+00:00 2026-06-13T06:05:50+00:00

Please suppose you have a table called BEER_HERE, with two columns: BEER_CODE VARCHAR(50) BEER_DATE

  • 0

Please suppose you have a table called BEER_HERE, with two columns:

BEER_CODE VARCHAR(50)
BEER_DATE DATETIME

Please suppose also you have the availability of a function called dbo.TRUNCATE_DATE which works as follows:

dbo.TRUNCATE_DATE ('23/12/2012 23:59:57.395') ==> 23/12/2012 00:00:00.000

I would like to create a FUNCTION BASED INDEX on:

(BEER_CODE, dbo.TRUNCATE_DATE(BEER_DATE))

How could I achieve this?

Thank you in advance for your kind help.

  • 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-13T06:05:51+00:00Added an answer on June 13, 2026 at 6:05 am

    You would need to add a computed column

    Alter Table BEER_HERE Add Column XBEER_DATE As dbo.TRUNCATE_DATE(BEER_DATE)
    

    You can then index it as you’d expect.

    However, your function needs to be deterministic and precise as defined in http://msdn.microsoft.com/en-us/library/ms189292(v=sql.90).aspx. Your function should meet these requirements, but you might need to add With SchemaBinding to the function definition.

    You might also be able to use a view

    Create View V_BEER_HERE As Select BEER_CODE, BEER_DATE, dbo.TRUNCATE_DATE(BEER_DATE) As XBEER_DATE From BEER_HERE
    Create Unique Clustered Index PK_V_BEER_HERE On V_BEER_HERE (BEER_CODE)
    Create Index I_XBEER_DATE On V_BEER_HERE (XBEER_DATE)
    

    Stuff that inserts writes to the table, stuff that reads reads from the view. This depends on BEER_CODE being a primary key.

    SQL Server doesn’t have function based indexes the same way Oracle does.

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

Sidebar

Related Questions

In a SQL SERVER 2005 database, please suppose we have a table called RUNNING_COLA_IS_AFRICA.
Please suppose that I have a table with a certain, unspecified number of columns.
Suppose we have a table with UserID ,Calendar date and taskName as columns. Please
Suppose I have the following two tables in my MySQL database: Table 1:: EMP:
Suppose I have a table with columns id, name, phone_type, phone_no and I have
Ok, let's suppose we have members table. There is a field called, let's say,
I have a table called Area, that stores areas in a hierarchical manner. There
Suppose that I have a table Attendances (id(integer), login_date(date), login_time(time),logout_time (time)). Now I have
Suppose, I have a table like this- Code | something ------------------ C01 abc C02
Suppose I have the following two tables: STUDENT studentid lastname firstname 1 Smith John

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.