Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Selecting rows according to todays date.

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2013-08-20 : 10:13:45
I have to select rows based on if the transaction date = todays date.

The column is defined as numeric 8 with 0 decimal.

Can you show me how to code for todays date with such a column?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-08-20 : 10:20:17
quote:
Originally posted by AdamWest

I have to select rows based on if the transaction date = todays date.

The column is defined as numeric 8 with 0 decimal.

Can you show me how to code for todays date with such a column?

Can you give some examples of the data? For example, how is today's date represented in the numeric 8 column?
Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2013-08-20 : 10:23:40
yes, on the server it is represented as this:

19,991,216




quote:
Originally posted by James K

quote:
Originally posted by AdamWest

I have to select rows based on if the transaction date = todays date.

The column is defined as numeric 8 with 0 decimal.

Can you show me how to code for todays date with such a column?

Can you give some examples of the data? For example, how is today's date represented in the numeric 8 column?

Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-08-20 : 10:45:33
quote:
Originally posted by AdamWest

yes, on the server it is represented as this:

19,991,216




quote:
Originally posted by James K

quote:
Originally posted by AdamWest

I have to select rows based on if the transaction date = todays date.

The column is defined as numeric 8 with 0 decimal.

Can you show me how to code for todays date with such a column?

Can you give some examples of the data? For example, how is today's date represented in the numeric 8 column?



I am not familiar with that representation of dates. What is the formula/process you would use to convert 19,991,216 to August 20, 2013?

If you don't have that information, hopefully someone else on the forum may know.
Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2013-08-20 : 10:54:39
James, I am not looking to convert the date.

I am looking for select only the current date. I am going to make a VIew, so that the Crystal Report would only get the current date. The user runs this every day and is only interested in the current date. so it would only select 20,130,820 if run today.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-08-20 : 11:19:20
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Here is one way:
SELECT CAST(CONVERT(VARCHAR(8), GETDATE(), 112) AS DECIMAL(8,0))

Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2013-08-20 : 12:02:14
What is GETDATE? is that for the current date?
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-08-20 : 12:23:50
Yes, GETDATE gets you current date and time. You will see what it does if you run the query "SELECT GETDATE()". The CONVERT function formats that to a string according to the format specifier (112) in this case: http://technet.microsoft.com/en-us/library/ms187928.aspx
Go to Top of Page

corbingravely
Starting Member

1 Post

Posted - 2013-12-13 : 04:53:39
You can do this using the foreign key. You can set the unique Id as the one you prefer to be the reference point and call the rest of the table objects using that key as the major object.







Go to Top of Page
   

- Advertisement -