if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GETPROP_LAST_CHANGED]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[GETPROP_LAST_CHANGED] GO SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO CREATE PROCEDURE GETPROP_LAST_CHANGED @ID int,@OFFICE_ID int AS CREATE TABLE #result_table( LAST_CHANGED DATETIME, rea_id varchar(255), rea_status varchar(255), rea_date datetime ); declare @LAST_CHANGED datetime set @LAST_CHANGED = (select isNull(LAST_CHANGED,'19000102') from prop where id = @ID and office_id = @OFFICE_ID); insert into #result_table (LAST_CHANGED) values(@LAST_CHANGED); update #result_table set rea_id = (select Isnull(portal_id,'') from prop_rea_import where id = @ID and office_id = @OFFICE_ID); update #result_table set rea_status = (select Isnull(status,'') from prop_rea_import where id = @ID and office_id = @OFFICE_ID); update #result_table set rea_date = (select Isnull(em_date,'') from prop_rea_import where id = @ID and office_id = @OFFICE_ID); select * from #result_table; drop table #result_table; GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO