# Stored query vars not bound with BIND

**URL:** https://community.stardog.com/t/stored-query-vars-not-bound-with-bind/3032
**Category:** Support
**Created:** [May 8, 2021, 6:29am UTC](https://community.stardog.com/t/stored-query-vars-not-bound-with-bind/3032 "2021-05-08T06:29:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nicholsn](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicholsn/32/284_2.png) [@nicholsn](https://community.stardog.com/u/nicholsn)
#### Post date: [May 8, 2021, 6:29am UTC](https://community.stardog.com/t/stored-query-vars-not-bound-with-bind/3032/1 "2021-05-08T06:29:56Z")

</div>

I am trying to create a unique label for instances of a certain type by binding one of the strings returned by a stored query. The query looks something like this:

```auto
SELECT ?my_label ?record_label ?my_label_extended ?my_record_extended ?my_label_record
WHERE {
    SERVICE <query://my-query> { 
            [] sqs:vars ?my_label, ?my_table
            }
    GRAPH <virtual://my-database> {
          ?record a ?my_table ;
                rdfs:label ?record_label .
          BIND (CONCAT(STR(?my_label), "-Record-") AS ?my_label_extended)
          BIND (CONCAT("Record-", STR(?record_label)) AS ?my_record_extended)
          BIND (CONCAT(STR(?my_label), "-Record-", STR(?record_label)) AS ?my_label_record)
    }
}

```

The results will bind the values for `?my_label`, `?record_label`, and `?my_record_extended` but not `?my_label_extended` or `my_label_record`. So it looks like there is some issue using BIND with `sqs:vars`.

Placing the CONCAT directly in the SELECT as a variable works to overcome this, but I am trying to return this label in a CONSTRUCT query so I believe using BIND is the correct/only option.

Any thoughts on what might be going on here?

---

<div class="post-metadata">

### Author: ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)
#### Post date: [May 8, 2021, 7:22am UTC](https://community.stardog.com/t/stored-query-vars-not-bound-with-bind/3032/2 "2021-05-08T07:22:19Z")

</div>

Hi Nolan,

Can you show the query plan? It kind of looks like that your BIND statements should be outside of the `GRAPH <virtual://my-database> {..}` block, otherwise the SQS variables aren't bound when those BINDs are evaluated.

Cheers,  
Pavel

---

<div class="post-metadata">

### Author: ![nicholsn](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/nicholsn/32/284_2.png) [@nicholsn](https://community.stardog.com/u/nicholsn)
#### Post date: [May 8, 2021, 3:54pm UTC](https://community.stardog.com/t/stored-query-vars-not-bound-with-bind/3032/3 "2021-05-08T15:54:05Z")

</div>

Hi Pavel,

Thanks! I took a look at the query plan and the problem variables were not present. I tried your suggestion and moved the BIND to the outer scope and that solved the issue =)

Cheers,

Nolan

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [May 22, 2021, 3:54pm UTC](https://community.stardog.com/t/stored-query-vars-not-bound-with-bind/3032/4 "2021-05-22T15:54:45Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
