I have this procedure :
CREATE PROC dbo.##HTMLtoMARKDOWN @text nvarchar(500),
@returnText nvarchar(500) output
AS
BEGIN
DECLARE @counter tinyint
SET @counter=1
WHILE CHARINDEX('**', @text, 1) > 0
BEGIN
SELECT @text = STUFF(@text,
CHARINDEX('**', @text, 1),
2,
IIF(@counter%2=0,'<br><b>','</b>')),
@counter = @counter + 1
END
SET @returnText = @text
END
GO
Which can be run like this:
DECLARE @returnText nvarchar(500)
EXEC dbo.##HTMLtoMARKDOWN '**a** **b** **c**', @returnText output
I'm using this kind of query:
Select, IIF(IsUniversal=0,'TRUE','FALSE') as [Is Universal?],
MarkdownMini as [Off Topic Reason]
From CloseAsOffTopicReasonTypes
group by IsUniversal, MarkdownMini
Ifdbo.##HTMLtoMARKDOWN
was declared as a function (CREATE FUNCTION dbo.HTMLtoMARKDOWN @text nvarchar(500))
), I could have written this:
Select, IIF(IsUniversal=0,'TRUE','FALSE') as [Is Universal?],
dbo.HTMLtoMARKDOWN(MarkdownMini) as [Off Topic Reason]
From CloseAsOffTopicReasonTypes
group by IsUniversal, MarkdownMini
I'm not allowed to use functions, so how I can do that kind of thing with a temporary procedure?
To update rows using a stored procedure, you need cursor:
If you intent to return a record set (like select), you need a temp table or in-memory table:
The SET NOCOUNT ON/OFF are required if you want to return the row to a caller such as C#, PHP, where you also want to make above lines into one stored procedure.
This one works by applying the stored procedure to the distinct reasons rather than processing the whole set.