SQL question replacing  case statement  TSQL SQL server 2000

indikad used Ask the Experts™
Appreciate if someone can do a quick QA on this code and let me know if I am on the right track.

the SQL belongs to a stored procedue of a large Web system. I do not have the development enviorenment for the entire system, but need a change to one of the stored prcedures so its kind of very hard to do full testing.

the existing code extracts a hard coded string (DCode)  depending on the Descr in the ClassMaster table.  But new requirements are DCode can change. So we built a new table with a link to ClassMaster ( DGCodes ). The new table cotains the DCode that the user can edit.

I just want to make sure the new SQL code does teh same job as before.

here is the table structure
DGCodes table
ClassId			Descr		DCode
000000001G00000001YN	A	                 1
0000000033000000001M	B	                 2
00000000880000000014	C	         	3

ClassMaster  table
ClassId			Descr						 
000000001G00000001YN	A	                 
0000000033000000001M	B
00000000880000000014	C

Open in new window

here is the Existing code
		case c.Descr 
			When 'A' then '1'
			When 'B' then '2'	
			When 'C' then '3'			
			else ''
		end as DCode
	from ClassMaster c join PartMain im on c.ClassId = im.ClassId

Open in new window

here is the new code
Select 	DGCodes.DCode 			 
	from DGCodes join join PartMain im on im.ClassId = DGCodes.ClassId

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
As per my understaing you want to k=just remove teh hardcoded values from query and take it from table value

your code is correct only you have wrtiien to time join make it once

Select       DGCodes.DCode                   
      from DGCodes join  PartMain im on im.ClassId = DGCodes.ClassId


pratima_mcs : thanks for the reply.

yes the "join" - it was a typo when placing the edited code in here.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial