1

I'm trying to run this query - SELECT count (*) FROM [WorkflowTotals01] where [E1] like '%wfname%'

The wfname is a variable that's populated from another list. We need to use a like command, but am unable to figure out how to use like with a variable.

2
  • Not clear where you want to use wfname as variable. If in sql then please mention the which DBMS because it changes for each one of them like in sql server you can do like '%'+@wfname+'%'. If in the code then concatenate the string with variable. Commented Aug 4, 2015 at 20:19
  • What rdbms is this ? Inferring from the python tag, if you're creating a sql string then cant you just create the statement with concatenating your variable wfname ? Commented Aug 4, 2015 at 20:22

1 Answer 1

1

Below is your query string that you should use to pass into your db cursor. Pass the variable as an argument into your script. or you can just set it

Pass

query = "SELECT count (*) FROM [WorkflowTotals01] where [E1] like '%{0}%'".format(sys.argv[1])

Set

blah = "hello"
query = "SELECT count (*) FROM [WorkflowTotals01] where [E1] like '%{0}%'".format(blah)

Set from a List

query = "SELECT count (*) FROM [WorkflowTotals01] where [E1] like '%{0}%'".format(list[0])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.