title: Cosmos DB: Dynamic Input and Output in Stored Procedure
body: <p>I am new to stored procedure in Cosmos DB. But what I want is to do dynamic input and output in CosmosDB.</p>
  
  <p>For example, we have a data model 'Student' where </p>
  
  <pre><code>{
          "FirstName": "Jack",
          "LastName": "Louis",
          "ZipCode": "12345"
      }
  </code></pre>
  
  <p>I want to be able to query any of these dynamically:</p>
  
  <pre><code>SELECT FirstName, LastName FROM Student WHERE FirstName = "Jack"
  SELECT FirstName, ZipCode FROM Student WHERE LastName= "Louis"
  SELECT ZipCode FROM Student WHERE ZipCode = "12345"
  </code></pre>
  
  <p>I did some research and found out I still have to use SQL Query inside the stored procedure function.For <a href="https://stackoverflow.com/questions/26665767/simple-documentdb-stored-procedure">example</a>:</p>
  
  <pre><code>function(gender) {
    var context = getContext();
    var response = context.getResponse();
    var collection = context.getCollection();
    var collectionLink = collection.getSelfLink();
  
    var filterQuery = 'SELECT * FROM c WHERE c.gender = "' + gender + '"';
  
    collection.queryDocuments(collectionLink, filterQuery, {},
      function(err, documents) {
        response.setBody(response.getBody() + JSON.stringify(documents));
      }
    );
  }
  </code></pre>
  
  <p>The filterQuery variable is the SQL Query and I cannot think of how to do dynamic input/output in this.. </p>
  
  <p>Any suggestions or thoughts? Thanks!</p>