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
 SELECT statement Help

Author  Topic 

dbserver2000
Starting Member

47 Posts

Posted - 2009-05-01 : 17:11:10

I am trying to practice to get better :)


Q- Using AdventureWorks: Write a SELECT statement retrieving a list of all employees with Birthdays in the next month.

What is the format of the date for such a statement should be?

dbserver2000
Starting Member

47 Posts

Posted - 2009-05-01 : 17:17:50
Firstname, LastName is in Person.contact

birthdate is in HumanResources.Employee

Thanks for your help
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-05-02 : 09:50:07
select firstname + ' '+ lastname, birthdate
from Person.contact c
inner join
HumanResources.Employee e on e.employeeid = c.employeeid
where month(birthdate) = month(getdate())+1
and year(birthdate) = year(getdate())
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-02 : 23:31:49
quote:
Originally posted by bklr

select firstname + ' '+ lastname, birthdate
from Person.contact c
inner join
HumanResources.Employee e on e.employeeid = c.employeeid
where month(birthdate) = month(getdate())+1
and year(birthdate) = year(getdate())



I don't think this query will give you the lists of employee whose birthday is next month. That employee(s) will only be born next month and what kind of company would employ infant even before they are born


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dbserver2000
Starting Member

47 Posts

Posted - 2009-05-02 : 23:55:47
Well I got an error message running that Query

I am still stuck though
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-03 : 07:57:44
[code]
select firstname + ' '+ lastname as name,
birthdate
from Person.contact c
inner join HumanResources.Employee e
on e.ContactID = c.ContactID
where month(birthdate) = month(getdate())+1
[/code]

For the next time: Please copy and paste the error message...

Greetings
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dbserver2000
Starting Member

47 Posts

Posted - 2009-05-03 : 16:03:36
Here is the error message that I should have included

Msg 207, Level 16, State 1, Line 4
Invalid column name 'employeeid'.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-03 : 17:18:35
Yes I know. Thanks.
My solution above should work.

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dbserver2000
Starting Member

47 Posts

Posted - 2009-05-03 : 22:12:40
WbFred

greatly appreciated. It works, BUT I have no clue what does:

+' '+ stands for

Also

from Person.contact c inner join HumanResources.Employee e

What does the c and e stand for.

I sound like an ignorant, but I am, not that I am proud of it.

Thanks

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-04 : 01:30:26
quote:
Originally posted by dbserver2000

WbFred

greatly appreciated. It works, BUT I have no clue what does:

+' '+ stands for
concatenate firstname +'one space'+ lastname

Also

from Person.contact c inner join HumanResources.Employee e

What does the c and e stand for.
alias for the tablename. So you can type c.ContactId instead of Person.contact.ContactId

I sound like an ignorant, but I am, not that I am proud of it.

Thanks






No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -