title: Set Variable value in exists condition sql server
body: <pre><code> Declare @CategoryID as int
  BEGIN  
      SELECT 
      (CASE 
          WHEN EXISTS(
              SELECT t0.Categoryid AS [EMPTY]
              FROM Categories AS [t0]
              WHERE [t0].Categoryname = @CategoryName
             ) THEN 1
          ELSE 0
       END) AS [value]
  </code></pre>
  
  <p>if i want to set my variable inside exists block with t0.Categoryid how could i do that ?</p>
  
  <p>what i want is to replace <strong>then 1</strong> to the <strong>category id value...</strong></p>
  
  <p>thanks in advance..</p>