Search those records that contain % character in there value
The code below is to search those records where first name contains % character. This question also important for interview
/* Search those
records where first name contains % */
CREATE TABLE #userdata (RecordId INT IDENTITY, FirstName VARCHAR(50), LastName VARCHAR(50))
INSERT INTO #userdata (FirstName, LastName) VALUES ('Dave%', 'Hanks'), ('Simon', 'Deja'), ('Peter%', 'Hans')
SELECT * FROM #userdata
/* Query 1 */
SELECT * FROM #userdata WHERE CHARINDEX('%', FirstName, 0) > 0
/* Query 2 */
SELECT * FROM #userdata WHERE FirstName LIKE '%[%]%'
DROP TABLE #userdata
Thanks!
ReplyDeletehttp://www.meshcreation.com