Python Multiline String Changes The Indentation
I'm working on a Automation with Python and Selenium. I have to paste a block of SQL & Java Script codes within the Text Area in the website. I used many ways to send the strin
Solution 1:
The solution to this problem is very simple. You just copy pasted the SQL Query hoping that it'll work here as it is. The thing here in Python is that it is indent sensitive. a wrong indent would cause a unintended trouble. Now, on the other hand SQL Queries and JavaScript Code, both of there are not indent sensitive. These depend on ; (semicolon) to break the line. This means that even if you specify 300 commands in one line separating each one with a ; (semicolon) the commands will execute without hassles. But the same won't work here in case of python.
If you try the below code, this will work for you and you'll get the expected results.
prdrsql1 = ("SELECT DISTINCT CAST(q2.SubjectId AS varchar(32)) as SubjectId, q2.SubjectNum, 'A' as ItemOid, q1.B as VisitId, q1.[C] as VisitRepeatKey, q1.[D] AS FormOid, q1.E as FormRepeatKey, 'Y' as Data FROM Table.A.ABC q2 wit (NOLOCK) Right Join ( select hashkey, SubjectNum, (CASE WHEN C is null THEN 'SUBJECT' ELSE [D] END) AS [D], (CASE WHEN G is null THEN 'SUBJECT' ELSE [G] END) AS [G], FormOID, [DD], AB,ABCfrom Table.A.ABC with (NOLOCK) where abc=123) q1 on q1.abc = q2.qbc AND q1.AA = 1 and AAA=1")
Try printing and verifying the output of this variable in your SQL Client before actually using it.
Post a Comment for "Python Multiline String Changes The Indentation"