Solved

Convert field value in select statement

Posted on 2012-03-15
5
186 Views
Last Modified: 2012-12-02
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
0
Comment
Question by:markloessi
5 Comments
 
LVL 25

Accepted Solution

by:
jogos earned 500 total points
ID: 37725774
select dose
, case dose when 1 then '40 MG = 1 ECTAB'
    ELSE dose
  end as changed_dose
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 37726150
what is your current query? we may suggest something better depending on your current solution...
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 37726154
what about updating your table

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

then your query should be fine...
0
 
LVL 31

Expert Comment

by:awking00
ID: 37730344
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.
0
 

Author Comment

by:markloessi
ID: 37735775
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Truncate vs Delete 63 90
Word Template Mail merge with vb.net 4 40
combine an MS SQL string in Idera DM 9 31
SQl query 19 14
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now