• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

select case change 2 column values

I am using the below SQL sytax to add a dummy column and move vales to that column.
SELECT        ID, WO_Number, ItemID, QtyUsed, Units, Feet, CASE WHEN Feet > 0 THEN Feet ELSE QtyUsed END AS QtyUsed2
FROM            TRX_ROW_INV_DRI

what also need to do is that when Feet > 0, also move Units to another dummy column 'Units2' and then change the value to 'FT'.

Any idea on how to accomplish this?
0
vwalla
Asked:
vwalla
  • 2
  • 2
1 Solution
 
sdstuberCommented:
somethnig like this?

SELECT        ID, WO_Number, ItemID, QtyUsed, case when feet > 0 then 'Ft' else units end as Units, Feet, CASE WHEN Feet > 0 THEN Feet ELSE QtyUsed END AS QtyUsed2, case when feet > 0 then units end as units2
FROM            TRX_ROW_INV_DRI
0
 
vwallaAuthor Commented:
Got.  It was easier than I thought.

SELECT        ID, WO_Number, ItemID, QtyUsed, Units, Feet, CASE WHEN Feet > 0 THEN Feet ELSE QtyUsed END AS QtyUsed2,
                         CASE WHEN Feet > 0 THEN 'FT' ELSE Units END AS Units2
FROM            TRX_ROW_INV_DRI
0
 
vwallaAuthor Commented:
We posted at the same time, but you were quicker! Thanks!
0
 
gplanaCommented:
Not sure if I fully understood your question, but you can execute this select:

SELECT        ID, WO_Number, ItemID, QtyUsed, Units, Feet, CASE WHEN Feet > 0 THEN Feet ELSE QtyUsed END AS QtyUsed2, CASE WHEN Feet > 0 THEN Units ELSE NULL END AS Units2
FROM            TRX_ROW_INV_DRI

What do you mean about change the value to FT ?
0
 
sdstuberCommented:
your conditions don't seem to correspond to your explanation.


>>>>>  when Feet > 0, also move Units to another dummy column 'Units2' and then change the value to 'FT'.

>>CASE WHEN Feet > 0 THEN 'FT' ELSE Units END AS Units2

This will move units to unit2 when feet <= 0  or when feet is null

is that really what you want?


in any case,  it seems you're on the right track,  just make sure your > and < are correct.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now