title: Calling a User-defined Scalar function within an Execute Statement
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4936180/cast-integer-and-concatenate-to-varchar-in-tsql">Cast integer and concatenate to varchar in TSQL</a>  </p>
  </blockquote>
  
  
  
  <p>I have created two scalar functions that each return <code>uniqueidentifer</code> types. I need to call these procedures in an execute statement but I seem to have syntax wrong. </p>
  
  <pre><code>Exec spModifyProductPropertyValue 
       @PAVID, 
       fnGetPropertyIDbyLabel(@Label7, @USPID, 0, 1), 
       @ProductID, 
       @Value7, 
       fnGetPINID(@7PIN), 
       0, 
       @counter out
  </code></pre>
  
  <p>What I notice is that when I call the function separately and then pass use the output from theprevious call in the call above, like so </p>
  
  <pre><code>Declare
        @PropertyID as uniqueidentifier = null
  
  Select @PropertyID = fnGetPropertyIDbyLabel(@Label7, @USPID, 0, 1)
  
  Exec spModifyProductPropertyValue 
           @PAVID, 
           @PropertyID, 
           @ProductID, 
           @Value7, 
           fnGetPINID(@7PIN), 
           0, 
           @counter out
  </code></pre>
  
  <p>The compiler does not complain much. Problem with this approach is that I end up creating so many of these temp variables(almost 50), something I want to try to avoid. I would appreciate any help in getting this correct please.</p>