Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using new columns created from PARSENAME

I have split the column PointName using PARSENAME and created 2 new columns and I am needing now to use a WHERE clause to only pull the data for those 6 types. Is there a way to do this?

SELECT *, reverse(PARSENAME(REPLACE(REVERSE(pointname),'.','.'),2))as [Type] , reverse(PARSENAME(REPLACE(REVERSE(pointname),'.','.'),3))as [Point] 
from RawAnalog RA
Where ra.PointName LIKE '%SKYLINE%'
      and ra.Point IN ('MaTmp', 'OaTmp', 'SaTmp', 'ChwVlv','SaStp', 'SaCFM')

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Filling in the blanks a bit, but I would guess you could move the PARSENAME to the FROM and then you can filter more easily in the WHERE:

SELECT {Columns you need},
       V.[Type],
       V.Point
FROM dbo.RawAnalog RA
     CROSS APPLY(VALUES(REVERSE(PARSENAME(REPLACE(REVERSE(pointname), '.', '.'), 2)),REVERSE(PARSENAME(REPLACE(REVERSE(pointname), '.', '.'), 3))))V([Type],Point)
WHERE RA.PointName LIKE '%SKYLINE%'
  AND RA.Point IN ('MaTmp', 'OaTmp', 'SaTmp', 'ChwVlv', 'SaStp', 'SaCFM')
  AND V.[Type] IN ({List of acceptable values});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading