Avatar of indikad
 asked on

SQL question replacing case statement TSQL SQL server 2000

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

Microsoft SQL Server

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

pratima_mcs : thanks for the reply.

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

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy