title: Insert data based on non existence and different criteria's
body: <p>I'm trying to add a row to my table only on two conditions but when inserting it retrieves error and I cannot figure it out</p>
  <pre><code>
   Create PROC [dbo].[setvisitorqueue]
   @pid bigint = null , @vid int = NULL ,@regdate nvarchar(50)  =NULL 
  
   AS 
  
   declare @queNum int =null
   set @queNum = (select max([ticketNo]) + 1 from [dbo].[queue] where [ticketdate]= GetDate())
   if( @queNum is null) begin  set @queNum=1 end
  
   Declare @Tktt int = null  
  
   set @Tktt = (select count(queue.ticketid) from queue where (queue.pid = @pid )and (queue.ticketdate = GetDate()) and (queue.vid = @vid and queue.checked = 0))
  
   if (@Tktt is null ) 
   begin insert into queue (vid , pid , ticketNo , ticketdate ) Values (@Vid,@pid,@queNum,@regdate ) end
  
  </code></pre>
  <p>Its not working for me.</p>