x
login about faq Site discussion (meta-askssc)

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 20 23 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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x321
x4

asked: Jul 14 '10 at 10:02 AM

Seen: 602 times

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

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.