title: Conversion failed : converting from a character string to uniqueidentifier
body: <p>I have the following function which returns the following result set when this string is called.</p>
  
  <pre><code>SELECT item 
  FROM dbo.DelimitedSplit8K('985B773F-5E36-47D4-9E84-E0CE35B34337,32237666-86F3-41FD-BCDE-794571CDAEA2',',')
  </code></pre>
  
  <p>Result set:</p>
  
  <pre><code>item
  ------------------------------------
  985B773F-5E36-47D4-9E84-E0CE35B34337    
  32237666-86F3-41FD-BCDE-794571CDAEA2
  </code></pre>
  
  <p>Now the purpose of this function is to get the two or more IDs cause I will be passing multiple IDs from my C# program to one variable in my stored procedure.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>The problem seems to be simple enough but I am not sure as to why it's occurring. </p>
  
  <pre><code>CREATE PROC [dbo].[usp_printMulitTest]
      @multiApplicationId_FK uniqueidentifier = '',
      @pDelimiter CHAR(1) = NULL
  AS  
      ;WITH image_CTE(imgBinary, imgCode, appID) AS
      (
          SELECT 
              [image], imageCode_FK, app
          FROM   
              [dbo].Images  
          WHERE 
              CAST('985B773F-5E36-47D4-9E84-E0CE35B34337,32237666-86F3-41FD-BCDE-794571CDAEA2' AS UNIQUEIDENTIFIER) 
                  IN ((SELECT item 
                       FROM dbo.DelimitedSplit8K(CAST('985B773F-5E36-47D4-9E84-E0CE35B34337,32237666-86F3-41FD-BCDE-794571CDAEA2' AS UNIQUEIDENTIFIER),',')))
       )
       SELECT * 
       FROM image_CTE
  </code></pre>
  
  <p>This stored procedure works fine when I hard code the variables.</p>
  
  <p>However, when I convert it to this </p>
  
  <pre><code>WHERE CAST(app AS UNIQUEIDENTIFIER) 
     IN((SELECT item FROM dbo.DelimitedSplit8K(CAST(@multiApplicationId_FK AS UNIQUEIDENTIFIER),','  )))
  </code></pre>
  
  <p>to get the results for the app IDs that I pass in, I get an error</p>
  
  <blockquote>
    <p>Conversion failed when converting from a character string to uniqueidentifier</p>
  </blockquote>
  
  <p>While looking for solutions two that were pointed out is the incorrect formation of the unique identifier and not using cast, however I checked the numbers and used a cast/convert and there has been no change.</p>
  
  <p>Grateful for assistance in this.</p>