1

I have a col ProductName in my Select statement which has a String which has a attached string "-Sales" for e.g. peter -Sales. Now I want my result to remove that -Sales and just show peter. How can i do it.I am just pasting my select part of my query as my query has many inner join

SELECT
dbo.Customer.firstName+' '+dbo.Customer.lastName        AS FirstName,
 CONVERT(VARCHAR(10), dbo.Receipt.receiptDate,105)       AS SaleDate,
dbo.Receipt.transactionNumber AS TransactionNumber,
dbo.Receipt.description        AS ProductName,
2
  • String Functions (Transac-SQL) Commented Nov 14, 2012 at 9:32
  • Will it always be -Sales or do you want to strip out everything after the last -? Commented Nov 14, 2012 at 9:36

1 Answer 1

3

you can use REPLACE

SELECT REPLACE(dbo.Customer.firstName+' '+dbo.Customer.lastName, '-Sales',''),...
FROM...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.