Note that there are some explanatory texts on larger screens.

plurals
  1. POextracting certain part of string in SQL stored procedure
    primarykey
    data
    text
    <p>I have this stored procedure at the moment. I would like to limit the String ChanceOfSuccess to only a the percentage like "40%". Right now the string reads something like this "40% - Thinking about it". What would be the best way to do this?</p> <pre><code>CREATE PROCEDURE [dbo].[procActivity_SelectbyOutstandingActivitiesNew] AS SELECT C.[Name] AS [Customer], C.CustomerId AS [CustomerID], E.FirstName + ' ' + E.Surname AS [Employee], AT.[TypeName] AS [Activity Type], A.[ActivityDate] AS ActivityDate, A.NextActivityDate, A.[ChanceOfSuccess] AS ChanceOfSuccess, A.[Comments] AS Comments, U.Surname + ' ' + U.FirstName AS [User], E.EmployeeId, A.ActivityId, CONVERT(INT, SUBSTRING(A.ChanceOfSuccess, 0, CHARINDEX ('%',A.ChanceOfSuccess))) AS [Success Percentage], A.[IsComplete] FROM Customer C INNER JOIN Activity A ON A.CustomerId = C.CustomerId INNER JOIN Employee E ON E.EmployeeId = A.EmployeeId AND E.CustomerId = C.CustomerId INNER JOIN [ActivityType] AT ON A.[ActivityTypeId] = AT.[ActivityTypeId] INNER JOIN [User] U ON A.[UserId] = U.[UserId] LEFT OUTER JOIN Activity A2 ON A.CustomerId = A2.CustomerId AND A.UserId = A2.UserId AND A2.ActivityDate &gt; A.ActivityDate WHERE C.[IsDeleted] = 0 AND A.NextActivityDate &lt;= GETDATE() AND E.IsDeleted = 0 AND A.IsDeleted = 0 AND (A2.ActivityId IS NULL OR A2.IsDeleted &gt; 0) AND CONVERT(INT, SUBSTRING(A.ChanceOfSuccess, 0, CHARINDEX ('%',A.ChanceOfSuccess))) &lt; 100 ORDER BY A.NextActivityDate ASC, Customer, A.ActivityDate ASC, [Success Percentage] DESC GO </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload