Use Sql Where with a collection

  • 3 October 2018
  • 3 replies
  • 1 view

Badge +4

Hi Everyone

I have a sharepoint list which retutns me some name; I store this name in a collection

After that; I'd like to execute a sql querry like that:

Select [Role], [Name],[Incoming]

FROM MyDB

WHERE Name IN mycollection

When I execute this WF; I get the following error message: Incorrect Syntax near 'Bob' (Bob is a name which is in my collection)

Any idea of what I'm doing wrong?

Thanks


3 replies

Badge +5

The SQL syntax for a where .. in is

Where Name in ('Firstname','Secondname','Thirdname')

So you would need to Join your collection values with ',' into a string and add (' at the start and ') at the end

You should then be able to use this string in your Where expression

Badge +4

Sorry for the delay, I built a string and I get the following string:

 

('Bob','Julien','Tom')

So it's exactly what I need but during my querry I get the following error message:

Incorrect syntax near 'Bob'.

And here my query :

SELECT [Role]
,[Name]
FROM [dbo].[Stakeholders]
WHERE '{Common:ProjectUID}' = ProjectUID AND [Name] IN {WorkflowVariable:MName}

If I replace  {WorkflowVariable:MName} by  ('Bob','Julien','Tom')

Any idea of what I'm doing wrong?

Badge +5

Try this

set MName to 'Bob','Julien','Tom'

Then make your query

SELECT [Role]
 ,[Name]
 FROM [dbo].[Stakeholders]
 WHERE '{Common:ProjectUID}' = ProjectUID AND [Name] IN ({WorkflowVariable:MName})

That is, make the brackets part of the query and not part of the string

Reply