Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Passing single quotes to a variable - used in SQL where statement

Problem: I need to store a date in a variable used in SQL Where statement but the single quotes around the date do not come through.

I have a variable that pulls a date used as the earliest date I want to pull data for.

tStartDate:

LOAD

     max(DataStartDt) as DataStartDt

FROM

Calendar.qvd

(qvd);

Let vStartDate = Peek('DataStartDt');

in this case vStartDate = 40544    (translating to the date   1/1/2011)

-----------------------------------

The date is then used in the vIncrementalExpression which holds the Where in my SQL statement.

LET vIncrementalExpression = 'WHERE dataDate >=' & date($(vStartDate), 'MM/DD/YYYY');

-----------------------------------

Used in SQL

TableName:

SQL SELECT *

FROM testData

$(vIncrementalExpression)

----------------------------------

This translates to this in SQL

SQL SELECT *

From testData WHERE dataDate >= 01/01/2011

NOTICE the missing single quotes around the date.  This needs to be

SQL SELECT *

From testData WHERE dataDate >= '01/01/2011'

Thank you for your help

1 Solution

Accepted Solutions
Sokkorn
Master
Master

Hi darrin,

Maybe this one can do your job. Let try

LET vIncrementalExpression = 'WHERE dataDate >=' & Chr(39) & date($(vStartDate), 'MM/DD/YYYY') & Chr(39);

Regards,

Sokkorn

View solution in original post

2 Replies
Sokkorn
Master
Master

Hi darrin,

Maybe this one can do your job. Let try

LET vIncrementalExpression = 'WHERE dataDate >=' & Chr(39) & date($(vStartDate), 'MM/DD/YYYY') & Chr(39);

Regards,

Sokkorn

Anonymous
Not applicable
Author

Sokkorn,

Thank you very much.  I can't believe I didn't think of that and thought it would be something very simple.

Thanks for the quick response.