Ignoring first few characters in a TSQL Select

  • I have a SQL that get me a count of rows that have a column name = the parameter that i am passing in.

    SELECT COUNT(*) FROM Content_T WHERE Name = $[[=] CName]

    Some of the values for Name in the database have a prefix attached to them "AUTO_" that i need to ignore. How i modify my SQL to ignore the prefix "AUTO_". Please note that not all the Name columnshave the AUTO_ prefix. If the name column do not have AUTO_ prefix i need do a regular match.

     

    Thanks for hte help

  • where replace(myName, 'AUTO_', '')  = @thisName

    or

    where CASE WHEN LEFT(myName, 5) = 'AUTO_' THEN RIGHT(myName, LEN(myName) - 5) ELSE myName END = @thisName

  • Thanks it worked...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply