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

Hugh Self Taught 101 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 Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
181 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 121.6K 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 Answers by the question author, which helps users to know the answer solved the author's problem.