| 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.contactbirthdate is in HumanResources.EmployeeThanks for your help |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-02 : 09:50:07
|
| select firstname + ' '+ lastname, birthdate from Person.contact cinner join HumanResources.Employee e on e.employeeid = c.employeeidwhere month(birthdate) = month(getdate())+1and year(birthdate) = year(getdate()) |
 |
|
|
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 cinner join HumanResources.Employee e on e.employeeid = c.employeeidwhere month(birthdate) = month(getdate())+1and 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] |
 |
|
|
dbserver2000
Starting Member
47 Posts |
Posted - 2009-05-02 : 23:55:47
|
| Well I got an error message running that QueryI am still stuck though |
 |
|
|
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 cinner join HumanResources.Employee e on e.ContactID = c.ContactIDwhere month(birthdate) = month(getdate())+1[/code]For the next time: Please copy and paste the error message...GreetingsWebfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
dbserver2000
Starting Member
47 Posts |
Posted - 2009-05-03 : 16:03:36
|
| Here is the error message that I should have includedMsg 207, Level 16, State 1, Line 4Invalid column name 'employeeid'. |
 |
|
|
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. |
 |
|
|
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 forAlso 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 |
 |
|
|
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'+ lastnameAlso 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.ContactIdI 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. |
 |
|
|
|