title: Is there a better way to find a specific value in dynamic query?
body: <p>I'm trying to find out is there a value in a dynamic query, at the moment I'm using this solution:</p>
  
  <pre><code>DECLARE 
    @SQL NVARCHAR(MAX)
  , @ISLN NUMERIC(9,0) = '967272'
  SET @SQL = 
  'SELECT * 
  FROM ITEM 
  LEFT OUTER JOIN SHIPMENT_DETAIL 
  ON ITEM.ITEM = SHIPMENT_DETAIL.ITEM 
  AND (SHIPMENT_DETAIL.COMPANY = ITEM.COMPANY OR ITEM.COMPANY IS NULL)  
  WHERE (SHIPMENT_DETAIL.warehouse = N''SH'' ) 
  ORDER BY ITEM.ITEM  ASC'
  SELECT @SQL = STUFF (
      @SQL
      , 8
      , 1
      , 'INTERNAL_SHIPMENT_LINE_NUM'
  )
  DECLARE @TEMP TABLE (ISLN NUMERIC(9,0))
  INSERT INTO @TEMP (ISLN)
  EXEC SP_SQLEXEC @SQL
  IF EXISTS (SELECT 1 FROM @TEMP WHERE ISLN = @ISLN)
  SELECT 1
  ELSE 
  SELECT 0
  </code></pre>
  
  <p>Dynamic SQL is generated by other software, so I cannot change the input data.</p>
  
  <p>Is there a better way to find specific value in specific column of a dynamic query?</p>