0

Wasnt really sure how to phrase this title, every time I think I have this figured out it always comes back to trip me up.

I am using B1 Boyum and storing a string in a variable.

The code looks like this

@STORE30 = '(T3.ItmsGrpNam LIKE 'Comm%%' OR T3.ItmsGrpNam = 'Vended Ancillary' OR T3.ItmsGrpNam = 'Merchant Fee and CC' OR T3.ItmsGrpNam = 'Laundry P&A')'

However this gives me unexpected END errors, ive tried escaping with + on either side of the first one ('Comm%%') which doesnt give me the unexpected end error but stops the string at T3.ItmsGrpNam LIKE

I need to have the whole string including the apostrophes of each of in between.

One day I will get the hang of this, happy to read some resources on best practices if someone can also supply some links.

Nick Jones
  • 93
  • 8
  • Does this answer your question? [How do I escape a single quote in SQL Server?](https://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-server) – nyedidikeke Feb 10 '21 at 02:42
  • Hi @nyedidikek, tried the doubling up of quotes, didnt work – Nick Jones Feb 10 '21 at 02:59

2 Answers2

0

Did you try this?

@Store30 = '(T3.ItmsGrpNam LIKE ''Comm%%'' OR T3.ItmsGrpNam = ''Vended Ancillary'' OR T3.ItmsGrpNam = ''Merchant Fee and CC'' OR T3.ItmsGrpNam = ''Laundry P&A'')'

When you want to escape the single quotes just use a double single quotes there.

leandroian
  • 64
  • 4
  • Yeah I tried doubling up on apostrophes. end result is just ```T3.ItmsGrpNam LIKE``` , it doesnt even get to 'Comm%%' ... – Nick Jones Feb 10 '21 at 02:57
  • Are you sure? I'm trying this in my MSSQL `DECLARE @STORE30 AS NVARCHAR(MAX) = '(T3.ItmsGrpNam LIKE ''Comm%%'' OR T3.ItmsGrpNam = ''Vended Ancillary'' OR T3.ItmsGrpNam = ''Merchant Fee and CC'' OR T3.ItmsGrpNam = ''Laundry P&A'')' PRINT @Store30` And i get this **(T3.ItmsGrpNam LIKE 'Comm%%' OR T3.ItmsGrpNam = 'Vended Ancillary' OR T3.ItmsGrpNam = 'Merchant Fee and CC' OR T3.ItmsGrpNam = 'Laundry P&A')** – leandroian Feb 10 '21 at 03:06
  • could it have something to do with it being a macro in B1 Usability Package? I swear ive come across this before and there was a solution but for the life of me i cant remember.. – Nick Jones Feb 10 '21 at 03:09
0

Figured it out

@STORE30 = SQL(SELECT 'T3.ItmsGrpNam LIKE ''Comm%%'' OR T3.ItmsGrpNam = ''Vended Ancillary'' OR T3.ItmsGrpNam = ''Merchant Fee and CC'' OR T3.ItmsGrpNam = ''Laundry P&A''')
Nick Jones
  • 93
  • 8