How to calculate birth year in SQL Server [closed] - sql-server

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
In TSQL, how can the year of birth be calculated?
I have tried datediff options but to no avail.
Thanks in advance for any thoughts.

If you only have age, you have already lost information. you can never know for sure the year of birth. This will approximate the YOB
dateadd(yy,-Age,CURRENT_TIMESTAMP)
You could slightly improve the accuracy of this guess by trying to adjust for the probability of whether the individual has had a birthday this year.
dateadd(yy,case when month(current_timestamp) <= 6 then 0 else 1 end-Age,CURRENT_TIMESTAMP)
You will want to substitute CURRENT_TIMESTAMP for the time that the age metric was acquired if you are retro-applying this to an existing dataset (assuming that data is available).
Above all, I would recommend changing your process to capture date of birth upfront if possible.

Related

Row numbers for consecutive dates for a given activity [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
I need to return row numbers for consecutive dates for each activity.
enter image description here
I have tried row_number() over(partition by) but cannot seem to get the right row numbers against the consecutive dates for the activity type. This is what I am trying to return:
enter image description here

my project has diffrent result every time [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I wrote this code in my project but every time i run it the answer is diffrent.
]1
Initialize sum with a value of 0. The reason it is different every time is you are calling sum which you never assigned a value. Anything could be in memory where sum is stored, which is why your results are inconsistent.

Can anyone translate this into python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
dow(m,d,y) {
y-=m<3;
return(y+y/4-y/100+y/400+"-bed=pen+mad."[m]+d)%7;
}
The function's purpose is to find what day(Su-Sa) will the provided date(1-31) land on in any given month and year.
I'm not sure how this function works because it was written in C. Mostly I don't know what
the y-=m<3 is for, or what the "-bed=pen+mad." does (is this just a string?).
here is my source: https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html
Just use the python datetime module:
import datetime
dayOfWeek = datetime.datetime(y, m, d).weekday()
dayOfWeek will then be an integer between 0 and 6 corresponding to Monday - Sunday.
Have a look at the docs for more details.

How to convert this MS SQL numeric value to a date [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Should be an easy convert, but cast and convert are failing me.
The value I am trying to convert is: 1509180600
Other examples are 1572256200, 5150938920
I have a very large number of records and many fields where dates have been stored like this. The system is being replaced, which means thankfully, this problem will go. But need to know what the values are before wiping them!
This is probably a Unix timestamp. You can convert it by adding seconds to 1970-01-01:
select dateadd(second, col, '1970-01-01')
. . .

Sum of row Depending on data in sql server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a table which store Customerid, amount and vouchartype this is a transaction table which store multiple entry for a single customer. vouchartype is 'D' for debit and 'C' for Credit and all amount have positive value. Now I want to sum of Individual customer debit value should be subtract from Credit value.
Please help me
Here is one solution. Everything other than 'C' is considered positive. You might need to reverse the sign depending on what you need.
SELECT
Customerid,
sum(case when vouchartype = 'C' THEN -amount ELSE amount END) As AMount
FROM YOurTable
GROUP BY Customerid

Resources