Share via

Is Select x like %(% as newname possible in a query

Hugh Self Taught 106 Reputation points
2025-05-07T08:39:39.28+00:00

I have the following query that produces correct results however since UnRegMale or UnRegFemale may be bracketed in which case I need to select that field as '' in the query. Bracketed names in the table are not competitors but support persons whose names should not be visible. Is this possible in this query. Something similar to the use of ISNULL(x,'')

SELECT LTRIM(REPLACE(REPLACE(H.PtsNonMale,'.',' '),'  ',' ')) AS UnRegMale, LTRIM(REPLACE(REPLACE(H.PtsNonFemale,'.',' '),'  ',' ')) AS UnRegFemale, C.Comp_Name As Competition, convert(int, YEAR(C.Comp_Date),103) As [Comp Date], E.EvtDesc As Section, H.PtsPlaced as Placed
	FROM tblPtsPerCompHistory H
	LEFT JOIN tblEvtStructure E ON E.EvtStruct_Idx = H.PtsStructID
	LEFT JOIN tblCompetitions C ON H.PtsCompID = C.Competition_Idx
	WHERE H.PtsMale = 0 And H.PtsFemale = 0 And ISNULL(H.PtsNonMale,0) <> '0' And H.PtsNonMale <> '' And ISNULL(H.PtsNonFemale,0) <> '0' And H.PtsNonFemale <>''
	ORDER BY LTRIM(H.PtsNonMale), LTRIM(H.PtsNonFemale), C.Comp_Date DESC

SQL Server | SQL Server Transact-SQL
0 comments No comments

Answer accepted by question author

  1. Viorel 126.9K Reputation points
    2025-05-07T08:58:55.75+00:00

    Maybe like this:

    SELECT case when H.PtsNonMale like '%(%' then '' else LTRIM(REPLACE(REPLACE(H.PtsNonMale,'.',' '),'  ',' ')) end AS UnRegMale,
    . . .
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.