i try to write insert and update query in one store procedure, in if else statement , but it is only taking the else statement and executing, in if else statement i'm just comparing the current date with the date from the table. 
USE [DBase] GO /****** Object: StoredProcedure [dbo].[Companies_UpdateViews] Script Date: 05/27/2012 13:13:49 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Companies_UpdateViews] @company_id int AS declare @views int declare @last_view_date datetime declare @current_date datetime declare @last_view_count int select @views =[views] + 1 from companies where id=@company_id select @last_view_date =[last_view_date] from companies where id=@company_id select @last_view_count=[last_view_count] + 1 from companies where id=@company_id SET @current_date= GETDATE() BEGIN UPDATE Companies SET [views]=@views WHERE id =@company_id END IF (@last_view_date = @current_date) ...

Go to the complete details ...