Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a sql server table contains this data:EmpCode Month Year Field1 Field2---------------------------------------------------------------------------------------QT351 April 2009 45 23QT351 March 2009 67 43QT555 March 2009 67 12QT555 April 2009 54 32QT351 April 2008 45 23QT555 March 2007 67 12--------------------------------------------------------------------------------------Can you please help me to write a Transact-SQL command to get records from the table where field1 in Arpril but Field2 in March like this result:EmpCode Month Year Field1 Field2---------------------------------------------------------------------------------------QT351 April 2009 45 43QT555 April 2009 54 12--------------------------------------------------------------------------------------
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2009-04-28 : 21:35:08
use table alias
select a.EmpCode, a.Month, a.Year, a.Field1, m.Field2from table1 a inner join table1 m on a.EmpCode = m.EmpCode and a.Year = m.Yearwhere a.Month = 'April'and m.Month = 'March'
KH[spoiler]Time is always against us[/spoiler]
chungpn
Starting Member
8 Posts
Posted - 2009-05-13 : 21:28:08
quote:Originally posted by khtan use table alias
select a.EmpCode, a.Month, a.Year, a.Field1, m.Field2from table1 a inner join table1 m on a.EmpCode = m.EmpCode and a.Year = m.Yearwhere a.Month = 'April'and m.Month = 'March'