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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2009-04-28 : 16:03:16
Query required

Table:State

Stid desc
---- -----
22 GA
32 NY
42 CA


Table:Trans

StudentID Fees Resd
--------- ---- -----
1000 1000 GA
2000 500 CA
3000 500 NY


I need an output like below


StudentID Fees Resd
--------- ---- -----
1000 1000 22
2000 500 32
3000 500 42

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-28 : 16:04:42
SELECT t.StudentID, t.Fees, s.Stid AS Resd
FROM Trans AS t
INNER JOIN State AS s ON s.desc = t.Resd



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-04-29 : 04:24:45
try this too
SELECT t.StudentID, t.Fees, (select stid from state where desc = t.Resd) AS Resd
FROM Trans AS t
Go to Top of Page
   

- Advertisement -