title: SQL Server : use bigint variable in stored procedure
body: <p>Very simply, I am calling a procedure to get the primary key from one table, then storing the key in a variable so that I can then use it to insert into another table that needs a foreign key. The variable is what I expect it to be, however when I use it it returns nothing.</p>
  
  <p>After trying looking at it, it appears to be that its an issue with the <code>WHERE</code> clause and using the variable</p>
  
  <pre><code>DECLARE @ClientId bigint;
  
  SELECT * 
  FROM Testing.dbo.Client 
  WHERE ClientID = @ClientId
  </code></pre>
  
  <p><code>@ClientId</code> value is 2</p>
  
  <p>There is a value of 2 for a as a client ID in the table</p>
  
  <p>When I run this I get the result I expect </p>
  
  <pre><code>select * 
  from Testing.dbo.Client 
  where ClientID = 2
  </code></pre>
  
  <p>This is where it gets set </p>
  
  <pre><code>DECLARE @ClientId int;
  EXECUTE @ClientId = Testing.dbo.GetClientID @ClientName;
  </code></pre>
  
  <p>Where GetClientID is the following</p>
  
  <pre><code>USE Testing
  GO
  CREATE PROCEDURE GetClientId
      @ClientName nvarchar(50)
  AS 
      SELECT ClientID FROM Testing.dbo.Client WHERE ClientName = @ClientName
  GO
  </code></pre>
  
  <p>Worked out a bit more now, so the ClientId is not getting set after call to the proc</p>