Avatar of markloessi
markloessi
Flag for Afghanistan asked on

Convert field value in select statement

I have data which looks like this, I'm trying to get accurate counts (TRANS_QTY_SUM) based on dose and unfortunately some of the doses are stored as '1' (complicated reason for this). In reality the items which are '1' are really the same as the items with a dose of '40 MG = 1 ECTAB'. Is there a way in the select statetment to convert the 1 to '40 MG = 1 ECTAB' or is there something more complex I'll need to do before executing this query to convert those doses. If so, then how do I do that, aka the if this store this.

Convert Dose in Select statement
Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
markloessi

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
jogos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
HainKurt

what is your current query? we may suggest something better depending on your current solution...
HainKurt

what about updating your table

update mytable set dose='40 MG = 1 ECTAB' where dose=1

then your query should be fine...
awking00

How is trans_qty_sum based on dose, given that dose is obviously a character field? There must be some sort of manipulation to the dose values to accomplish that and, perhaps, that's where you might deal with the '1' value instead of the '40 MG = 1 ECTAB' value.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
markloessi

ASKER
I ended up using the case when idea with a little twist in that i needed to accommodate a number of scenario's beside the 1 ECTAB example. I did this by reconstructing the 'dose' from the fields in another table where needed.
SELECT  CASE WHEN C.DOSE = '1' THEN P.STRENGTH + ' ' + P.STRENGTH_UNIT + ' = ' + +  P.PACKAGE_SIZE + ' ' + P.PACKAGE_UNIT 
			ELSE DOSE END AS CHANGED_DOSE,
	P.GENERIC_NAME, P.BRAND_NAME, P.THER_CODE_1, 
	(P.STRENGTH + P.STRENGTH_UNIT + ',  ' + P.VOLUME + P.VOLUME_UNIT + ',  ' +  P.PACKAGE_SIZE + ' ' + P.PACKAGE_UNIT) AS 'CONC - PACK INFO',
	C.*
	FROM CURES C
	JOIN PDM P
	ON C.DRUG_CODE = P.DRUG_CODE
	WHERE P.THER_CODE_1 = '56:28.36'
	AND C.TRANS_DATE >= GETDATE()-(180) 
	ORDER BY C.TRANS_DATE

Open in new window

Trans qty is not based on dose per se, at least it is not calculated from the value present here as dose, which is really a human readable form of dose. The TRANS_QTY is a billing field calcualated based on fields in the drug record which align with another table used to calculate a charge, so although dose and trans qty are related there are intermediary formulas that form the connection.