Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
adley51788
Contributor III
Contributor III

Utilizing a variable in a string to query SQL Server

I am looking to utilize an input parameter to query SQL Server. Having a little difficulty doing the following:

If I were utilizing SQL:

Select *

FROM Test

WHERE samplecolumn = ('concat_' + @Variable)

Trying in Qlikview:

select *

from Test

Where samplecolumn = ('concat_' $vVariable)

Getting an error because of the quotes being around the "Concat," but when trying to add around the variable, it is not considered.

1 Solution

Accepted Solutions
adley51788
Contributor III
Contributor III
Author

Figured it out.

where samplecolumn = 'Concat_$(vVariable)'

Thank you all for your assistance.

View solution in original post

7 Replies
trdandamudi
Master II
Master II

Not sure what you want, can you give more details. If you trying in Qlikview then hope below code helps:

select *

from Test

Where samplecolumn = '$(vVariable)'
Anil_Babu_Samineni

How about this

Load *

from Test

Where samplecolumn = ('concat_' & $(vVariable))

What Ares trying to achieve

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
adley51788
Contributor III
Contributor III
Author

I am trying to utilize a variable to complete a string to query on a where statement.

If I were utilizing SQL Server, the query would look like:

declare @Variable as nvarchar(4) = '9999';

Select *

FROM Test

WHERE samplecolumn = ('concat_' + @Variable)

The result would then be:

concat_9999

However, in qlikview, if I declare the variable, vVariable, it is giving me an error.

select *

from Test

Where samplecolumn = ('concat_' $vVariable)

I need Qlikview to take the variable, 9999, and concat for the where statement look like this:

where samplecolumn = 'concat_9999'

The result I am currently getting is:

where samplecolumn = 'concat_' 9999

Which is incorrect syntax for SQL Server.

adley51788
Contributor III
Contributor III
Author

Figured it out.

where samplecolumn = 'Concat_$(vVariable)'

Thank you all for your assistance.

trdandamudi
Master II
Master II

Create  vVariable in the Variable Overview as 9999

Load *

From Test

Where Samplecolumn='concat_' &'$(vVariable)';

There are also couple of ways:

Option I:

LET vVariable= 9999;

LOAD

     *

Where Samplecolumn='concat_' &'$(vVariable)';

SQL SELECT  *

FROM mydb.dbo.reps;

Option II

LET vVariable= 9999;

LOAD

     *

;

SQL SELECT  *

FROM mydb.dbo.reps

Where Samplecolumn='concat_' &'$(vVariable)';

Replace "mydb.dbo.reps" with your database and table. Hope this helps...

Not applicable

You might need to include the variable inside of the quotes.

Try it this way and see if it fixes the issue. It is working correctly on my machine:

SELECT  *

FROM Test

Where Samplecolumn = 'concat_$(vVariable)';

Anil_Babu_Samineni

sounds good, close this thread to put the flag Correct Answer.

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful