x

SQL Server Forums - How to calculate starsign(ex:sagittarius,tarus)

Hello

Can any one help getting this one.

I have two columns 1)date of birth 2)starsign(ex:tarus, gemini, sagittarius)like these.

My question is

if i enter the date of birth in the date of birth column. depending on that starsign column should be filled.

can any one send me the sqlserver query for this.

how can i solve it

thanks
more ▼

asked Jul 14 '10 at 10:02 AM in Default

sarathkumartata gravatar image

sarathkumartata
1 1 1 1

In order to do this in a query, you either need to store the dates that define the star signs, or you need to hard code them into the query. I'd suggest storing them.
Jul 14 '10 at 10:53 AM Grant Fritchey ♦♦
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

I'm not going to do all of these for you, but here is how I would basically handle that:

DECLARE @DOB datetime

set @DOB = '02/20/2010'

SELECT 
@DOB DOB, 
CASE WHEN (MONTH(@DOB) = 1 AND DAY(@DOB) >= 21)
         OR (MONTH(@DOB) = 2 AND DAY(@DOB) <= 19) 
         THEN 'Aquarius'
     WHEN (MONTH(@DOB) = 2 AND DAY(@DOB) >= 20) 
         OR (MONTH(@DOB) = 3 AND DAY(@DOB) <= 20) 
         THEN 'Pisces'
END
more ▼

answered Jul 14 '10 at 10:57 AM

Mark gravatar image

Mark
2.6k 21 25 27

+1 but you won't see it becuase I used up my alotment today. +1 in spirit.
Jul 14 '10 at 10:58 AM Grant Fritchey ♦♦
Thank you Grant. We're only alloted 5 a day?
Jul 14 '10 at 11:03 AM Mark
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x362
x6

asked: Jul 14 '10 at 10:02 AM

Seen: 886 times

Last Updated: Jul 14 '10 at 11:03 AM