Power BI Error Message

twildone

Board Regular
Joined
Jun 3, 2011
Messages
72
Hi,

I am getting an error message when I try and run the code in Power BI but it works when I run it in Microsoft SQL Server. What I am trying to do is create a proper case function to be used to correct a string of characters selected from another table. Any suggestions what I am not seeing....thanks

1738093348551.png


SQL:
DECLARE @SQL_CREATE NVARCHAR(MAX) = N'

IF OBJECT_ID('[dbo].[PCase]', 'fn') IS NOT NULL
  DROP function [dbo].[PCase];
go

CREATE FUNCTION [dbo].[PCase] 
(@Input as varchar(8000)) 
RETURNS varchar(8000) 
AS 
BEGIN 
DECLARE @Reset bit, 
@Proper varchar(8000), 
@Counter int,
@Input varchar(8000), 
@FirstChar char(1) 
SELECT @Reset = 1, @Counter = 1, @Proper = '' 
WHILE (@Counter <= LEN(@Input)) 
BEGIN 
SELECT @FirstChar = SUBSTRING(@Input, @Counter, 1), 
@Proper = @Proper + CASE WHEN @Reset = 1
                            THEN UPPER(@FirstChar)
                            ELSE LOWER(@FirstChar)
                            END, 
@Reset = CASE WHEN @FirstChar LIKE '[a-zA-Z]'
                THEN 0
                ELSE 1
                END, 
@Counter = @Counter + 1 
END 
SELECT @Proper = REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(@Proper)),' ',' '+ CHAR(7)) , CHAR(7)+' ',''), CHAR(7),'') 
WHERE CHARINDEX(' ', @Proper) > 0 
RETURN @Proper; 
END;
go
 
Last edited by a moderator:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You seem to have mismatched quotes. You have N' at the start and no closing quote that I can see. I'm not sure if you need to escape the quotes within the text too.
 
Upvote 0

Forum statistics

Threads
1,226,266
Messages
6,189,939
Members
453,583
Latest member
Ok_category1816

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top