Find rocord(s) from below table which contains last characters as 'aaa'?
ProductID ProductName
1 Fan aab
2 Fan abc
3 Fan g a
4 Fan g aaa
SELECT ProductId,SUBSTRING(ProductName, CHARINDEX('aaa',
ProductName, 1), LEN(ProductName)) AS Expr1, CHARINDEX('aaa',
ProductName, 1) AS indexid
FROM Products
WHERE (RIGHT(ProductName, 3) = 'aaa')
Result: 4 aaa 7
ProductID ProductName
1 Fan aab
2 Fan abc
3 Fan g a
4 Fan g aaa
SELECT ProductId,SUBSTRING(ProductName, CHARINDEX('aaa',
ProductName, 1), LEN(ProductName)) AS Expr1, CHARINDEX('aaa',
ProductName, 1) AS indexid
FROM Products
WHERE (RIGHT(ProductName, 3) = 'aaa')
Result: 4 aaa 7
No comments:
Post a Comment