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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:14:23+00:00 2026-06-18T02:14:23+00:00

First of all, I’m very new with SQL query, so I apologize if I

  • 0

First of all, I’m very new with SQL query, so I apologize if I sound ignorant…

I have a database that has a stored job to drop and create a table every hour. The table looks like this, except there is data for every hour in between 1 and 24

Name         Hour1  Hour24
Point 1 OUT  4      5
Point 1 IN   26     22
Point 2 OUT  46     44    
Point 2 IN   0      0
Point 3 OUT  18     19
Point 3 IN   56     51
Point 4 OUT  111    100
Point 4 IN   0      0
Point 5 OUT  0      0
Point 5 IN   42     46
Point 6 IN   210    211

After the drop and create, the database adds a column at the end called date and sets todays date as the default. My problem is when importing the data at 12:00am, the current date is actually tomorrow. For accounting purposes, I need that data to have the same day.

I took a shot in the dark and tried this, but the syntax is all wrong…

[Date] [datetime] DEFAULT if(DATEPART(hh)=24) CONVERT(GETDATE(DATEPART(dd)-1))

Is an if statement like this possible in a create table query? Is there a better way of going about this?

Thanks for the 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-18T02:14:24+00:00Added an answer on June 18, 2026 at 2:14 am

    Yes, you can set up a default value, but you want the syntax to be correct:

    [date] datetime default (case when datepart(hh, getdate()) = 24 then getdate() - 1 else getdate() end)
    

    However, I don’t think you should have a datetime value in a field called “date”. How about:

    AsOfDate date default (case when datepart(hh, getdate()) = 24 then cast(getdate() - 1 as date) else cast(getdate() as date) end)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I have to admit that these are very basic and primitive
First of all, apologize because I have seen some posts about this, but I
First of all, I'm using ARC. If I have a class that, for example,
can someone help in SQLite database in android ? First all,i have using tutorial
First of all I have seen that there are many questions about unrecognized selector
First of all, I'm quite new to the Android and JAVA world (coming from
First of all, let me say that I am not a professional coder -
I have movies table with movieID,movieName and movieDate. I want to select first all
First of all this is all just concept, I have no actual programming done
(First of all, sorry for my english, it's not my first language) I have

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.